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 :)

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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