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>" } Quote Link to comment 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> Quote Link to comment 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.