Bifter Posted August 14, 2010 Share Posted August 14, 2010 Hi, I have a form that once submitted some of its result are stored in arrays, example: (The form has multipul lines with the same input names) <select name="product[]"> once submitted goes into $_GET['product'] if I do: // Product ID's foreach($_GET['product'] as $name => $prodvalue) { print "$name : $prodvalue<br>"; } the following is returned: 0 : 9 1 : 10 2 : 11 3 : 12 Aswell as the Product ID's I have 2 other form input structured the same way, so my question is how do I loop through each of the $_GET's ($_GET['product'], $_GET['linequantity'] and $_GET['lineprice']) to add each of them to multipul SQL table rows? Also there will be other records that need to be entered, but, these will be constant, so for instance, if 3 rows are to be added then the other records will be the same for each of the 3 rows. Please help me, I'm goin' nuts! B. Quote Link to comment https://forums.phpfreaks.com/topic/210718-looping-through-multipul-arrays-and-inserting-into-sql/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 14, 2010 Share Posted August 14, 2010 Your $name variable is actually the array key and it ties all the related values to each other. Inside your existing foreach(){} loop, you can reference the other values using - $_GET['linequantity'][$name] $_GET['lineprice'][$name] Quote Link to comment https://forums.phpfreaks.com/topic/210718-looping-through-multipul-arrays-and-inserting-into-sql/#findComment-1099218 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.