Ok here goes,
I have a category table with the following columns:
cat_id
parent_id
cat_name
As you can see multiple level cateories.
ok so what I need to is extract the categories from the database in alphabetical order so imaging I have categories as follows:
Accessories
Accessories :: Parts
Accessories :: Parts :: PCB's
Accessories :: Parts :: Plugs
Accessories :: Leads
Amps & Speakers
Amps & Speakers :: Amplifiers
Amps & Speakers :: Amplifiers :: 4 Ohms
Amps & Speakers :: Amplifiers :: 8 Ohms
How would I extract them from the database in perfect alphabetical order as shown above.
Here's the code I am working with:
<SELECT NAME="cat_id">
<?
$sql = mysql_query("SELECT * FROM `categories` WHERE `parent_id` = '0'
ORDER BY `cat_name`; ");
while ($r = mysql_fetch_array($sql)) {
?>
<OPTION VALUE"<?php echo $r['cat_id']; ?>"><?php echo $r['cat_name']; ?></OPTION>
<?php } ?>
</SELECT>
So that would only give me the following:
Accessories
Amps & Speakers
What do I do inside that loop or what kind of table join should I use, bearing in mind that the levels could be infinate, and I need them in alphabetical order as I will have over 400 categories.
Can anyone help please?