Welcome Guest, Not a member yet? Register   Sign In
How to insert multiple rows from a single view.
#4

[eluser]bproctor[/eluser]
I'm not sure I understand exactly, but it sounds like you have a form with multiple rows, and three columns, the seller, number of sales and number of clients and you want to fill all these out and click submit and have all those rows be inserted into the database...

Code:
&lt;?php for ($i = 0; $i < 20; $i++) : ?&gt;
   <select name="seller[]">
      &lt;?php foreach ($sellers as $seller) : ?&gt;
         <option value="&lt;?php echo $seller->id; ?&gt;">&lt;?php echo $seller->name; ?&gt;</option>
      &lt;?php endforeach ?&gt;
   </select>
   &lt;input type="text" name="num_sales[]" /&gt;
   &lt;input type="text" name="num_clients[]" /&gt;
&lt;?php endfor ?&gt;

Then simply insert the entire post array into the database...

Code:
$this->db->insert_batch('my_table', $this->input->post());

Or if you need to have finer control over the data going into the database you could run it though a loop, something like this...

Code:
$post = $this->input->post();
for ($i = 0; $i < count($post['seller']; $i++) {
   $this->db->insert('my_table', array('seller_id' => $post['seller'][$i], 'num_sales' => $post['num_sales'][$i], 'num_clients' => $post['num_clients'][$i]));
}


Messages In This Thread
How to insert multiple rows from a single view. - by El Forum - 08-06-2011, 08:38 PM
How to insert multiple rows from a single view. - by El Forum - 08-06-2011, 09:02 PM
How to insert multiple rows from a single view. - by El Forum - 08-06-2011, 09:21 PM
How to insert multiple rows from a single view. - by El Forum - 08-07-2011, 12:54 AM
How to insert multiple rows from a single view. - by El Forum - 08-12-2011, 08:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB