[thelist] using a mysql record set as a navigation

David Treves dwork at macam.ac.il
Thu Feb 6 02:51:01 CST 2003


Hi there,

I did a similar thing a few days ago in ASP. I have used only one table,
which contains:
categoryId - unique ID of the record
parentCategoryId - default is 0, but if the category is a sub-cateory the
value will point to the ID of the parent category.

in order to use this structure you will have to run a JOIN query on the same
table with aliases, which will allow you to treat the table like 2 separated
ones. The SQL goes something like this:

SELECT cats.name, subCats.name FROM categories cats LEFT JOIN categories
subCats on cats.categoryId = subCats.parentCategoryId .......

This method is useful when you KNOW that you are not going to have
differences between a Category and a Sub-Category. If in doubt use 2 tables.

My 2 Cents,
David Treves.

----- Original Message -----
From: "Andrew Maynes" <andrew at humanbehaviour.co.uk>
To: "Thelist at Lists. Evolt. Org" <thelist at lists.evolt.org>
Sent: Thursday, February 06, 2003 10:19 AM
Subject: [thelist] using a mysql record set as a navigation


> Hi All
>
> I am forever asking questions about php and knowing that there is a
solution but
> wanting to know not only the solution but also the opinions of you
professional
> developers.
>
> So here is the latest.  I have a set of records that are categories. A
query
> pulls all the records for category and in turn this are then <links> to
items of
> that said category.  Simple.  Ok here is the bit I want some feeback on.
I want
> to create another table (if this is the solution) and split the category
into
> groups, this is for the purpose of navigation.  So istead of having 30
> categories I will have X number of goups with categories in X group.
>
> Do I need to create another table to do this (as we did with the
ref_colour) or
> can I split the output in a simple way with creating a table.  I guess
that some
> form of id is needed to seperate the records?
>
> This is what I have:
>
> $result=mysql("$DBName","SELECT * FROM Category ORDER BY Category");
> fontFace("Arial","Select a category:<br><br>");
> echo "<ul>";
> while ($row  =  mysql_fetch_row($result)) {
> $Cat=$row[0];
> $CatID=$row[1];
> echo"<li><a href='$Relative/items.php?CA=$CatID&UID=$UID'>$Cat</a></li>";
>         }
> echo "</ul>";
>
> Andrew
>
> --
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !




More information about the thelist mailing list