petenaylor Posted November 18, 2010 Share Posted November 18, 2010 Hi all I need to combine these two scripts: Firstly, the following decides which out of the following list is selected based on its value in the mySQL table: <select name="pack_choice"> <option value="Meters / Pack"<?php echo (($result['pack_choice']=="Meters / Pack") ? ' selected="selected"':'') ?>>Meters / Pack (m2)</option> <option value="m3"<?php echo (($result['pack_choice']=="m3") ? ' selected="selected"':'') ?>>Meters / Pack (m3)</option> <option value="Quantity"<?php echo (($result['pack_choice']=="Quantity") ? ' selected="selected"':'') ?>>Quantity</option> </select> Although this works OK, I need it also to show dynamic values like this: select name="category"> <?php $listCategories=mysql_query("SELECT * FROM `product_categories` ORDER BY id ASC"); while($categoryReturned=mysql_fetch_array($listCategories)) { echo "<option value=\"".$categoryReturned['name']."\">".$categoryReturned['name']."</option>"; } ?> </select> I'm not sure if this is possible? Many thanks for your help. Pete Link to comment https://forums.phpfreaks.com/topic/219048-dynamic-lists-with-dynamic-selected/ Share on other sites More sharing options...
petenaylor Posted November 18, 2010 Author Share Posted November 18, 2010 Here's how, if anyone is interested: <select name="category"> <?php $r=mysql_fetch_array(mysql_query("SELECT * FROM `products` WHERE id='".$edit."'")); $listCategories=mysql_query("SELECT * FROM `product_categories` ORDER BY id ASC"); while($categoryReturned=mysql_fetch_array($listCategories)) { echo "<option value=\"".$categoryReturned['name']."\"".(($r['category']==$categoryReturned['name']) ? ' selected="selected"':'').">".$categoryReturned['name']."</option>"; } ?> </select> Link to comment https://forums.phpfreaks.com/topic/219048-dynamic-lists-with-dynamic-selected/#findComment-1135975 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.