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 Link to comment https://forums.phpfreaks.com/topic/145541-drop-down-box-with-optgroup-by-categories/ 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 Link to comment https://forums.phpfreaks.com/topic/145541-drop-down-box-with-optgroup-by-categories/#findComment-764107 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 Link to comment https://forums.phpfreaks.com/topic/145541-drop-down-box-with-optgroup-by-categories/#findComment-764110 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.