Quote:may i ask what what is wrong with this?
You forgot the square brackets in the field attribute inputs. So all fields will have the same settings for field type, auto increment and length.
Then, in the for next loop for the fields, you make dbforge create the same table over and over again.
The right approach is:
1. Fetch the table name
2. In the for next loop (why not foreach … ?) create the array with all fields and their attributes
3. After the loop, let dbforge create the table.
PHP Code:
$tblname = $this->input->post('tblname');
$fieldnames = $this->input->post('fld_name[]');
$fieldtypes = $this->input->post('fld_type[]');
$fieldauths = $this->input->post('fld_aut[]');
$fieldlengths = $this->input->post('fld_lgth[]');
$fields = array();
foreach ($fieldnames as $index=>$fieldname) {
$fields[] = array(
$fieldname => array(
'type' => $fieldtypes[$index],
'constraint' => $fieldlenghts[$index],
'auto_incremenet' => $fieldauths[$index],
),
);
}
$this->dbforge->add_field($fields);
$this->dbforge->create_table($tblname);