nuttycoder Posted August 11, 2007 Share Posted August 11, 2007 I am trying to get categories from the database and show them in a drop down list showing root category then their sub category underneath. my category table scheme is like this: id int name varchar parent_id int i have got the categories into a drop down list in a form using this code: <p>Select <span class="title">Categories</span> <?php $query = "SELECT * FROM cats"; $result = mysql_query($query) or die ("Couldn't execute query"); echo "<select name='id'>\n"; while ($row = mysql_fetch_array($result)) { extract($row); echo "<option value='$id'>$name\n"; } echo "</select>\n"; ?> so what i'd like in the drop down list would be like this: root cat1 sub1 sub2 sub3 root cat2 sub1 sub2 ...ect any advice on how to do this would be great thanks Quote Link to comment https://forums.phpfreaks.com/topic/64381-custom-drop-down-list/ Share on other sites More sharing options...
MadTechie Posted August 11, 2007 Share Posted August 11, 2007 i am note sure what your asking for? it seam you just want two drop down lists ? if so the 2nd list will work like the first! Quote Link to comment https://forums.phpfreaks.com/topic/64381-custom-drop-down-list/#findComment-321012 Share on other sites More sharing options...
nuttycoder Posted August 11, 2007 Author Share Posted August 11, 2007 what i mean is i have root categories what have a parent_id of 0 and sub categories that have a parent_id of the id of the category it belongs to and i'd like a drop down list showing all categories and sub categories which i'd like to be in a single drop down list in order by the root categories like: windows xp email internet security windows vista email internet security so when your selecting a category you know which root category it belongs to Quote Link to comment https://forums.phpfreaks.com/topic/64381-custom-drop-down-list/#findComment-321015 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.