Jump to content

html forms: showing sql result in select option list


bobocheez

Recommended Posts

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>

<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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.