Page 1 of 1
insert multi rows - (arrays)
Posted: Wed Apr 02, 2008 11:54 am
by csoreto
Hi,
I have a shopping cart confirmation page with this array - <?php echo $my_shopping_cart->product_detail[$i][0]['f_products_name']; ?>; first of all as the code comes from an PHP class (phpclasses.org) I do not know what means [0]; secondly how can I insert (in a MySQL table) the values of this array in one single query?
carlos soreto
Re: insert multi rows - (arrays)
Posted: Wed Apr 02, 2008 12:57 pm
by aceconcepts
I do believe that [0] is an index of an array - so basically [0] would be the very first item in that array as an array starts from 0 not 1.
In terms of adding multiple values into a database all you would need to do is loop your array - foreach or for etc...
Re: insert multi rows - (arrays)
Posted: Wed Apr 02, 2008 1:45 pm
by csoreto
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Thank you.
I have tried
for, but
my table continues empty.
##
code:
Code: Select all
$editFormAction = $_SERVER['PHP_SELF'];
or($i=0;$i<$my_shopping_cart->num_of_products_id;$i++){
$sql1=sprintf("INSERT INTO test_mysql (f_products_name) VALUES (%)",
GetSQLValueString($my_shopping_cart->product_detail[$i][0]['f_products_name'], "text"));
mysql_select_db($database_test, $test);
$result1=mysql_query($sql1, test) or die(mysql_error());
mysql_insert_id();
}
header("location:something.php");
##
With
for($i=0;$i<$my_shopping_cart->num_of_products_id;$i++){
the page does not redirect.
carlos soreto
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Re: insert multi rows - (arrays) - SOLVED
Posted: Sun Apr 06, 2008 7:59 am
by csoreto
Solved!
As 'aceconcepts' wrote the solution is to make a loop (for, etc.)...
The problem was in the database itself...
carlos soreto
Re: insert multi rows - (arrays)
Posted: Sun Apr 06, 2008 8:00 am
by John Cartwright
would you mind posting what you did to solve it, to benefit anyone else that comes along
p.s. please edit your original post's title to include [SOLVED]