trichards Posted May 15, 2010 Share Posted May 15, 2010 I am trying to combine the size and quantity array as a selection dropdown that displays (Size - Quantity) Ex: (Small - 10). Can I get some help writing the foreach loop. Table: Sizes: small,medium,large,xl Quantity: 10,10,0,10 Code: $q = mysql_query("SELECT * FROM products WHERE id='3'"); $r = mysql_fetch_array($q); // Get Sizes $sizes = $r['size']; $explode_size = explode(",", $sizes); // Get Quantity $quantity = $r['in_stock']; $explode_quantity = explode(",", $quantity); foreach ($explode_size as $sizes) && foreach ($explode_quantity as $quantity) { echo "<option value=\"\">".$sizes." - ".$quantity."</option>" } Link to comment https://forums.phpfreaks.com/topic/201883-foreach-help/ Share on other sites More sharing options...
trichards Posted May 15, 2010 Author Share Posted May 15, 2010 FIXED: Used array_combine <select name=""> <? $q = mysql_query("SELECT * FROM products WHERE id='3'"); $r = mysql_fetch_array($q); $sizes = $r['size']; $explode = explode(",", $sizes); $quantity = $r['in_stock']; $explodeq = explode(",", $quantity); $array = array_combine($explode, $explodeq); //print_r($array); foreach ($array as $explode => $explodeq) { ?> <option value="<? echo $explodeq; ?>"><? echo $explode; ?> - <? echo $explodeq; ?></option> <? } ?> </select> Link to comment https://forums.phpfreaks.com/topic/201883-foreach-help/#findComment-1058834 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.