Welcome Guest, Not a member yet? Register   Sign In
codeigniter unable to insert multiple row data to database
#4

Instead of this code in your view:
PHP Code:
echo "
  <input name=\"iddisc"
.$n."\" type=\"text\" value=\"".$iddisc."\" class=\"textbox\" />
  <input name=\"dname"
.$n."\" value=\"".$discount_name."\" type=\"text\"  />
  "

I recommend:
PHP Code:
echo form_input('iddisc[]',$iddisc[$n],'class="textbox"');
echo 
form_input('dname[]',$discount_name[$n]); 
since you are using CI's form helper anyway.
By using square brackets at the end of the input name, $this->input->post('iddisc'); will return an array with all the iddisc input fields.
To process this in your controller (or model), do this:
PHP Code:
$iddiscs $this->input->post('iddisc');
$dnames $this->input->post('dname');

foreach (
$iddiscs as $index->$idd) {
  $data[] = array(
    'iddiscount'   => $idd;
    'discountname' => $dnames[$index],
    'status'       => 1,
  );

Reply


Messages In This Thread
RE: codeigniter unable to insert multiple row data to database - by Wouter60 - 08-04-2015, 11:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB