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
insert multi rows - (arrays)
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: insert multi rows - (arrays)
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...
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)
~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:
##
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.
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:
Re: insert multi rows - (arrays) - SOLVED
Solved!
As 'aceconcepts' wrote the solution is to make a loop (for, etc.)...
The problem was in the database itself...
carlos soreto
As 'aceconcepts' wrote the solution is to make a loop (for, etc.)...
The problem was in the database itself...
carlos soreto
Last edited by csoreto on Mon Apr 07, 2008 6:23 am, edited 1 time in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: insert multi rows - (arrays)
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]
p.s. please edit your original post's title to include [SOLVED]