adrian28uk Posted January 17, 2008 Share Posted January 17, 2008 I am putting together a small test shopping cart. I have got the principles of how it works, however I have noticed that on a lot of carts you can update the quantities and press one update button to adjust the final qtys of all products before checking out. What I need to do is put the id and qty by creating an array which I can do by submitting the form. The first number in the array is the id of the product, and the second number is the new quantity, like so. <?php $quantities = array("789", "2", "790","3"); ?> This is the part where I get stuck. I need to split the first two numbers from the array and then assign these to the mysql statement using a for each loop and so on. I hope this makes some sort of sense. Quote Link to comment https://forums.phpfreaks.com/topic/86426-updating-text-fields/ Share on other sites More sharing options...
GingerRobot Posted January 17, 2008 Share Posted January 17, 2008 You'd be better off using the the id of the product as the key of the array, and the quantity required as the element. You could then use a foreach loop and do whatever you need to do. Quote Link to comment https://forums.phpfreaks.com/topic/86426-updating-text-fields/#findComment-441708 Share on other sites More sharing options...
adrian28uk Posted January 17, 2008 Author Share Posted January 17, 2008 Do you mean something like this 234,235,236 could be the ids of the products. 2,3,4 are the updated quantities for these ids $new_qty= array('234' => '2', '235' => '3', '236' => '4); Then use a foreach loop to echo out the results? I have managed to use foreach loop, the problem I had was extracting the id and qty so that I could put these in a MySQL query. The answer to my problem is probably staring me in the face. Quote Link to comment https://forums.phpfreaks.com/topic/86426-updating-text-fields/#findComment-441712 Share on other sites More sharing options...
pdkv2 Posted January 17, 2008 Share Posted January 17, 2008 instaid of using <?php $quantities = array("789", "2", "790","3"); ?> you can use <?php $quantities = array(array("789", "2"), array("790","3")); ?> this will be easier to iterate through the array element using the nested loop Rgds, Sharad Quote Link to comment https://forums.phpfreaks.com/topic/86426-updating-text-fields/#findComment-441720 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.