Creating Navigation Links

As you will quickly see, I’m quite new using php. I have been assigned the task of converting our website over from static html to database driven.

I believe I am over thinking my problem which is with trying to create the actual pages that will display the content for my nav links.

Do I have to physically create each page that the navigation links will point to or can I use a “categories” (name of main navigation table) id and have a categories.php page that will be populated with the main description and the information for the subcategories? The subcategories will be kept in their own table with appropriate descriptions and matched up with a catid column to the corresponding main nav links.

Would I then control the different “layout” of the categories page and subcategories page with if statements?

I keep thinking myself into circles. Thanks for any help.

Okay…

So, if I understand your problem:

  • You have a table called “categories” which basically is just a name and id.
  • You have a table called “subcategories” which basically has the link and a cat_id which references “categories”.

What you could do was query to get the subcategories in the specified categories.

So, what you can do is order those by cat_id, then you go through each row in your results. When you go to a row that has a new cat_id, you do the code for a new row.

Something like this:


$last_catid = -1;

while($row = mysql_fetch_array($results)) {
    if($row['cat_id'] != $last_catid) {
        if($last_catid != -1)
            echo('</ul>');

        $last_catid = $row['cat_id'];
        echo('<ul class="category"><li>');
    }

    echo('<li>{$row['subcat_link']}</li>');
}

echo('</ul>');

Hope that helps.