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