phpdragon Posted February 19, 2009 Share Posted February 19, 2009 I have made a shopping cart type application, when it comes to adding all the items into the db after finalising the order, how do you get it to loop thru and add each entry as a seperate entity eg item1 item1price item1qty item2 item2price item2qty etc etc this is the code I am trying but it only adds the last item in the cart so I dont seem to have it looping till all items are added, could someone please show me how to get it to add all items. current code // declare order product variables $ordersql="SELECT orderID FROM orders WHERE userID='$userID' ORDER BY orderID DESC LIMIT 1"; $resultorder=mysql_query($ordersql); $result_row=mysql_fetch_array($resultorder); $thisID=$result_row["orderID"]; $orderTable=$userID."_orders"; for ($basket_counter=0;$basket_counter<$ses_basket_items;$basket_counter++){ $price=sprintf("%01.2f",$ses_basket_price[$basket_counter]); $quantity=$ses_basket_amount[$basket_counter]; $code=$ses_basket_stockcode[$basket_counter]; $itemID=$ses_basket_id[$basket_counter]; $product=$ses_basket_name[$basket_counter]; $unit=sprintf("%01.2f",($price/$quantity)); // add item to users order table $sql="INSERT INTO $orderTable (orderID, name, productID, quantity, stockcode, price) VALUES ('$thisID', '$product', '$itemID', '$quantity', '$code', '$unit')"; $result=mysql_query($sql); } Quote Link to comment https://forums.phpfreaks.com/topic/145917-how-do-you-add-multiple-entries-to-db-from-form-processing/ Share on other sites More sharing options...
RichardRotterdam Posted February 19, 2009 Share Posted February 19, 2009 you could create a query that inserts multiple entries instead of doing a query multiple times. That would faster Quote Link to comment https://forums.phpfreaks.com/topic/145917-how-do-you-add-multiple-entries-to-db-from-form-processing/#findComment-766060 Share on other sites More sharing options...
phpdragon Posted February 19, 2009 Author Share Posted February 19, 2009 could you give me an example? Quote Link to comment https://forums.phpfreaks.com/topic/145917-how-do-you-add-multiple-entries-to-db-from-form-processing/#findComment-766071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.