Re: Reading unknown number of form variables -? need a hint/help..

From: Date: Fri, 08 Nov 2002 10:37:08 +0000
Subject: Re: Reading unknown number of form variables -? need a hint/help..
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-123346@lists.php.net to get a copy of this message
Its something like: $res=mysql_query("select item_id, quantity from carts where customer_id='$customer_id'"); // you might want to join with another table to get item names and others you need while(list($item_id,$quantity)=mysql_fetch_row($res)) { echo "<input name=\"quantity[$item_id]\" value=\"$quantity\"> } <input type="submit"> on the next page: foreach($_POST['quantity'] as $item_id => $quantity) { mysql_query("update carts set quantity='$quantity' where item_id='$item_id' and customer_id='$customer_id'"); } hope you get the general idea, all information you need (for any item), that is item_id and its quantity will be stored in one input field, then you need to loop the array and update rows. You only need to get the customer_id, best done with sessions Paul wrote:
Hi All: I have the following setup: The page contains multiple rows (something like a shoping cart) that consist of item_id, item_name, and item_quantity. Item Quantity is a text box that can be adjusted. I have a button to update all items..( I am using query and based on item_id I can update database..) The number of rows varies. My question is - I really do not know how to get variables and update multiple items in a database..I think I need to somehow grab them and place in array perhaps? I am really not sure..I do not want to reinvent the wheel..can some one give me hint? Is there a piece of code that I can look at it and learn from? Any help would be greatly appreciated Paul PS I also would like to place a checkbox (in every row) in the event the item must be deleted..


« previous php.general (#123346) next »