Help rendering unordered list from database records
Posted: Tue Dec 02, 2008 9:51 am
I need to output an unordered list from a bunch of database records.
The database table in question is called "pages" and holds records of pages in a content management system.
I would like some help writing the code that will query the table and output an unordered list which I then turn into a suckerfish menu with a little css.
The important columns from the pages table are as follows:
uid - unique identifier for the record
pid - the unique id of this record's parent record
title - the title of the page
pageType - a predefined value determining the page type (more on this later).
I'm pretty sure this is similar to the "breadth-first" recursive loops but having looked everywhere, I can only find a bunch of rather unhelpful pseudo code for Flash or C++ and not much else. Any php code I've seen is onvolved with searching directories and therefore not much help.
When the code begins executing, I will know the starting uid, pid and title and nothing else (although all I really need is the uid). To make things slightly more complicated, the code can't run all the way to the bottom of the tree. It can only run to one node before the bottom-most node. Fortunately the pageType field can be interrogated for this - all the pages on the last level that should be rendered will have a pageType of 4 (all other pages have a pageType of 1).
Now, I realise I could just stick in about a dozen nested loops to go through the lot just ignoring what's not needed but I'd much rather have something that was a little more intelligent and did as little work as needed to achieve the result - largely because the code is to be re-used and needs to cope with anything that's thrown at it.
So, can anyone be of assistance?
The database table in question is called "pages" and holds records of pages in a content management system.
I would like some help writing the code that will query the table and output an unordered list which I then turn into a suckerfish menu with a little css.
The important columns from the pages table are as follows:
uid - unique identifier for the record
pid - the unique id of this record's parent record
title - the title of the page
pageType - a predefined value determining the page type (more on this later).
I'm pretty sure this is similar to the "breadth-first" recursive loops but having looked everywhere, I can only find a bunch of rather unhelpful pseudo code for Flash or C++ and not much else. Any php code I've seen is onvolved with searching directories and therefore not much help.
When the code begins executing, I will know the starting uid, pid and title and nothing else (although all I really need is the uid). To make things slightly more complicated, the code can't run all the way to the bottom of the tree. It can only run to one node before the bottom-most node. Fortunately the pageType field can be interrogated for this - all the pages on the last level that should be rendered will have a pageType of 4 (all other pages have a pageType of 1).
Now, I realise I could just stick in about a dozen nested loops to go through the lot just ignoring what's not needed but I'd much rather have something that was a little more intelligent and did as little work as needed to achieve the result - largely because the code is to be re-used and needs to cope with anything that's thrown at it.
So, can anyone be of assistance?