Jump to content

custom drop down list


nuttycoder

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/64381-custom-drop-down-list/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/64381-custom-drop-down-list/#findComment-321015
Share on other sites

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.