Darkwoods Posted February 17, 2009 Share Posted February 17, 2009 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 Quote Link to comment Share on other sites More sharing options...
Darkwoods Posted February 17, 2009 Author Share Posted February 17, 2009 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 Quote Link to comment Share on other sites More sharing options...
Darkwoods Posted February 17, 2009 Author Share Posted February 17, 2009 i am making it complicated lool here what i want to change in the code i want to display the categories in the optgroup thats what i meant 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.