• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert array into database

#15
[eluser]newsun[/eluser]
Hi, not sure if you figured a way around this, but you were not passing a multi dimensional array, just a bunch of post fields which looked like one in name.

Code:
$_POST['bulb_type_id[0][2]']
for example was one of your variables you passed

You could iterate through them doing something like this:

Code:
for ($i=0;$i<$_POST['a_number_you_pass'];$i++) {
            
    $sql = array(
    reminder_id = $reminder_id,
    quantity = $_POST["quantity[$i][1]"],
    bulb_type_id = $_POST["bulb_type_id[$i][2]"],
    shatterproof = $_POST["shatterproof[$i][3]"],
    );
    $this->db->insert('line_items', $sql);    
}

I think this is more in the lines of what you re trying to do here, where you need to pass in the number of rows you have total from your ajax via a post variable which I called 'a_number_you_pass' I included the insert statement in the loop as I don't know if CI can take a multi-dimentional array and run multiple inserts like that, if so you can move it out and change $sql to $sql[] or $sql[$i]

Good luck.


Messages In This Thread
Insert array into database - by El Forum - 07-23-2008, 12:38 PM
Insert array into database - by El Forum - 07-24-2008, 08:30 AM
Insert array into database - by El Forum - 07-24-2008, 10:08 AM
Insert array into database - by El Forum - 07-24-2008, 10:25 AM
Insert array into database - by El Forum - 07-24-2008, 10:34 AM
Insert array into database - by El Forum - 07-24-2008, 10:38 AM
Insert array into database - by El Forum - 07-24-2008, 10:41 AM
Insert array into database - by El Forum - 07-24-2008, 10:43 AM
Insert array into database - by El Forum - 07-24-2008, 10:48 AM
Insert array into database - by El Forum - 07-24-2008, 11:00 AM
Insert array into database - by El Forum - 07-24-2008, 11:49 AM
Insert array into database - by El Forum - 07-24-2008, 12:04 PM
Insert array into database - by El Forum - 07-24-2008, 12:09 PM
Insert array into database - by El Forum - 07-24-2008, 01:44 PM
Insert array into database - by El Forum - 08-26-2008, 12:04 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.