Question : Insert Array into mysql

Below is the result I get when posting my shopping cart array. I was wondering how I insert them..I have five fields.

The first two always need to stay the same, client_ref and id

Then I have these to insert the array into

qty name item_id price..Any help would be greatly appreciated...thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
[jcart_item_qty] => Array
        (
            [0] => 1
            [1] => 1
            [2] => 1
        )

    [jcart_item_name] => Array
        (
            [0] => Baseball Mitt
            [1] => Hockey Stick
            [2] => Soccer Ball
        )

    [jcart_item_id] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 1
        )

    [jcart_item_price] => Array
        (
            [0] => 19.50
            [1] => 33.25
            [2] => 25.00
        )

Answer : Insert Array into mysql

Try something like this

Assuming shopping cart table name is 'shopping_cart' and assuming you have the db declared.
1:
2:
3:
4:
5:
6:
for ( $counter = 0; $counter <= (count($array)-1); $counter++) {
mysql_query("INSERT INTO shopping_cart
(qty, name, item_id, price) VALUES('".$array[jcart_item_qty][$counter]."', '".$array[jcart_item_name][$counter]."', '".$array[jcart_item_id][$counter]."' ,'".$array[jcart_item_price][$counter]."' ) ") 
or die(mysql_error());  

}
Random Solutions  
 
programming4us programming4us