1

I have a problem with posting dynamic text box data with code-igniter. I am going to do this using insert_batch() method.

view

<input name="qty[]" type="text" id="qty[]" size="5" maxlength="5" />
<input type="hidden" name="id[]" id="id[]" value="<?php echo $v_items->product_id ; ?>" />

In controller I have get array result like this;

public function submit_in()
 {
 $data = array(
 'id' => $this->input->post('qty'),
 'qty' => $this->input->post('id')
 );
 $data['title'] = 'Damage Product';
 $data['subview'] = $this->load->view('admin/cwh/stock_in', $data, true);
 $this->load->view('admin/_layout_main', $data);
 } 
array (size=3)
 'id' => 
 array (size=13)
 0 => string 'qw' (length=2)
 1 => string 'qw' (length=2)
 2 => string '' (length=0)
 3 => string 'qwqw' (length=4)
 4 => string '' (length=0)
 5 => string '' (length=0)
 6 => string 'q' (length=1)
 7 => string '' (length=0)
 8 => string 'wwq' (length=3)
 9 => string '' (length=0)
 10 => string '' (length=0)
 11 => string '' (length=0)
 12 => string 'qw' (length=2)
 'qty' => 
 array (size=13)
 0 => string '74' (length=2)
 1 => string '75' (length=2)
 2 => string '76' (length=2)
 3 => string '77' (length=2)
 4 => string '78' (length=2)
 5 => string '79' (length=2)
 6 => string '80' (length=2)
 7 => string '81' (length=2)
 8 => string '82' (length=2)
 9 => string '83' (length=2)
 10 => string '84' (length=2)
 11 => string '85' (length=2)
 12 => string '86' (length=2)
 'title' => string 'Damage Product' (length=14)

So i cant perform batch_insert() method using this array result. (I think my array result format is wrong)

My table structure is

product_data(**pid**,id,qty);
asked Oct 22, 2015 at 4:17

3 Answers 3

2

Manipulate your data before use

$this->db->insert_batch('my_table',$data);

This is my suggestion:

$arr_qty = $this->input->post('qty');
$arr_id = $this->input->post('id');
$i=-1;
foreach($arr_qty as $qty):
$i++;
 $data[] = array(
 'qty' => $qty,
 'id' => $arr_id[$i]
 );
endforeach;
// Then
$this->db->insert_batch('my_table',$data);

Tell me if it works.

answered Oct 22, 2015 at 4:28
Sign up to request clarification or add additional context in comments.

1 Comment

you may use if(!empty($arr_qty))
0

bulk insert you must loop in order to insert the bulk data

for($i = 0; $i < sizeof($_POST['name']);$i++)
{
 $name = $_POST['name'];
 $data = array(
 $name[$i];
 );
 // insert the query here for insert
}
answered Oct 22, 2015 at 4:26

Comments

0

Actually you assign wrong data

'id' => $this->input->post('qty'),//Wrong 'qty'
'qty' => $this->input->post('id') //wrong 'id'

ID ==QTY and QTY == ID

That is wrong in your code, It should be

'id' => $this->input->post('id'), //correct
'qty' => $this->input->post('qty') //correct
answered Oct 22, 2015 at 4:36

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.