graham23s Posted February 14, 2008 Share Posted February 14, 2008 Hi Guys, In a form i have 2 inputs: <td align=\"center\"><input type=\"hidden\" name=\"pid[]\" value=\"$product_id\"><input type=\"text\" name=\"q[]\" size=\"5\" value=\"$product_qty\"> i have put them in [] to make arrays, when submitted i catch the GET like: if($_GET['action'] == 'update') { $product_id_to_update = $_POST['pid']; $quantity_to_update = $_POST['q']; foreach($quantity_to_update as $value) { // update query // $queryupdate = "UPDATE `fcp_orders` SET `qty`='$value' WHERE `product_id`='$product_id_to_update'"; echo $queryupdate; echo ("<br />"); } } which displays this when echoed out: UPDATE `fcp_orders` SET `qty`='577' WHERE `product_id`='Array' UPDATE `fcp_orders` SET `qty`='277' WHERE `product_id`='Array' UPDATE `fcp_orders` SET `qty`='377' WHERE `product_id`='Array' which is half way there i need the product_id to be the actual integers, is there anyway i can combine the foreach to include them both at all? thanks guys Graham Link to comment https://forums.phpfreaks.com/topic/91167-foreach-when-using-2-arrays/ Share on other sites More sharing options...
kenrbnsn Posted February 14, 2008 Share Posted February 14, 2008 A better way would be to do this in your form: <?php echo '<td align="center"><input type="text" size="5" name="pid[' . $product_id . ']" value="' . $product_qty . '">'; ?> Then you could do: <?php foreach ($_POST['pid'] as $product_id => $value) { $queryupdate = "UPDATE `fcp_orders` SET `qty`='$value' WHERE `product_id`='$product_id'"; echo $queryupdate . "<br>\n"; }?> Ken Link to comment https://forums.phpfreaks.com/topic/91167-foreach-when-using-2-arrays/#findComment-467234 Share on other sites More sharing options...
Barand Posted February 14, 2008 Share Posted February 14, 2008 <?php foreach ($_POST['pid'] as $k => $prod) { $qty = $_POST['q'][$k]; $sql = "UPDATE `fcp_orders` SET `qty`= $qty WHERE `product_id`='$prod'"; mysql_query($sql); } Link to comment https://forums.phpfreaks.com/topic/91167-foreach-when-using-2-arrays/#findComment-467238 Share on other sites More sharing options...
graham23s Posted February 14, 2008 Author Share Posted February 14, 2008 Thanks a ton guys i'm sorted. Graham Link to comment https://forums.phpfreaks.com/topic/91167-foreach-when-using-2-arrays/#findComment-467253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.