Hi,
I'm trying to generate a dynamically constructed navigation menu. I want 3 different levels i.e. heading 1 > sub-heading 1 > sub-sub-heading 1. Each needs to be pulled from a MySQL table. Although I've found a way of doing this is appears to be quite crude and would appreciate any suggestions to improve it.
I need to be able to achieve the following:
1 - Three menu levels.
2 - Some kind of ordering process (rather than just alphabetical).
3 - No JavaScript - All PHP.
4 - Use the table to contruct 'you are here' site navigation as well as generating the navigation menu.
At preset the MySQL table is constructed as follows:
cat_id (primary key)
cat_name (e.g. heading 1)
subcat_name (e.g. sub-heading1)
subsubcat_name (e.g. sub-sub-heading 1)
sort order (no sure how I'm using this yet!)
(I know that there is no field for the target at present - this doesn't matter as it can be added simply once I've got the thing working)
menu.php is included within a template file (index.php) so it is loaded every time the page requested. The code basically works as follows:
{
Select distinct cats from db
While (still can retrieve heading) {
echo heading
select distinct sub-headings corresponding to heading from db
While (still can retrieve sub-heading) {
echo sub-heading
select distinct sub-sub-headings corresponding to sub-heading from db
While (still can retrieve sub-sub-heading) {
echo sub-sub-heading
}
}
}
Any help would be very much appreciated! How can I make this more effiecient? Is this an okay approach?
Tom