bobocheez Posted August 29, 2009 Share Posted August 29, 2009 How can the following code be altered so that the select options menu shows all of the subcat choices? This is just a form that queries the database first <?php include('config.php'); $query = "SELECT * FROM subcategories ORDER BY cat_id ASC"; $result = mysql_query($query) or die('Sorry, could not access the database'); mysql_num_rows($result); $subcat_id = $row['subcat_id']; $subcat = $row['subcategorie_name']; $cat_id = $row['cat_id']; ?> <form action="addchan2.php" method="post"> <select name="subcat"> <?php while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { $cat = $row['cat']; echo "<option value=\"$subcat\">$subcat</option>"; } ?> </select> <input type="text" name="chan"> <input type="text" name="subcat_id" value="<?echo"$subcat_id";?>"> <input type="text" name="cat_id" value="<?echo"$cat_id";?>"> <input type="submit" value="Add"> </form> Link to comment https://forums.phpfreaks.com/topic/172363-html-forms-showing-sql-result-in-select-option-list/ Share on other sites More sharing options...
ignace Posted August 29, 2009 Share Posted August 29, 2009 <select name="subcategory"> <optgroup label="category1"> <option value="subcategory1">Subcategory #1</option> <option value="subcategory2">Subcategory #2</option> </optgroup> </select> Remember that you can't create a optgroup inside a option therefor you can only go as deep as multiple subcategories for a category. Subcategories can not on their turn contain Sub-Subcategories. Note: optgroup is not selectable. Link to comment https://forums.phpfreaks.com/topic/172363-html-forms-showing-sql-result-in-select-option-list/#findComment-908875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.