Jump to content

drop down box with optgroup by categories


Darkwoods

Recommended Posts

hello guys i hope someone can help me with this

 

i have made a table with list of categories and categories content table and its working just fine but the thing is i want to display the categories in drop down with categories content for example like this

 

<select>
  <optgroup label="Cat1">
    <option value="1">Dogs</option>
    <option value="2">Cat</option>
  </optgroup>
  <optgroup label="Cat2">
    <option value="3">data1</option>
    <option value="4">data2</option>
  </optgroup>
</select>

 

could anybody help please thank you :)

 

okey guys i found a good code but i still need help from you

 

here is the code:

$sql = "SELECT id, name FROM specialty ORDER BY name";

$res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>");

echo "<SELECT MULTIPLE SIZE=9 value='multiselect' name='category'>\n";
echo "<option value=''>- select category -</option>\n"; 
$prev = '';
while (list($id, $name) = mysql_fetch_row($res)) {
    $gp = strtoupper($name{0});
    if ($prev != $gp) {
        if ($prev) echo "</optgroup>\n";
        echo "<optgroup label='$gp'>\n";
        $prev = $gp;
    }
    echo "<option value='$id'>$name</option>\n";
}
echo "</optgroup>\n</SELECT>\n";
?>

 

now what i want to change in this code is to select from table specialty_categories in the database and display the specialty table data to the related categories specialty_categories

 

i hope someone can help with this pleaseee

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.