Welcome Guest, Not a member yet? Register   Sign In
Add table and fieldname
#2

(This post was last modified: 02-16-2019, 02:47 AM by Wouter60.)

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); 
Reply


Messages In This Thread
Add table and fieldname - by jaysondotp - 02-15-2019, 07:31 PM
RE: Add table and fieldname - by Wouter60 - 02-16-2019, 02:45 AM
RE: Add table and fieldname - by InsiteFX - 02-16-2019, 04:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB