Jump to content

Archived

This topic is now archived and is closed to further replies.

chrziz

Categories with PHP

Recommended Posts

I am trying to figure out the best way create a categories system that can have unlimited sub categories with PHP and MySQL.

I tried a few different methods but I cannot get any to work properly.

So far what I have is a table with the following structure:
categories
-cat_ID
-cat_name
-parent_cat_ID

I am trying to figure out how to create a loop that when given a cat_ID it keeps on grabbing the parent_cat_ID and cat_name until it gets to the top.

Is this the best way of doing this or is there a simpler way?

Share this post


Link to post
Share on other sites
2 tables would be the best way to do what you need

cat_table:

cat_id
cat_description
blah
blah
blah

sub_cat_table

sub_id
cat_id
sub_description
blah
blah
blah

Now put all your main catagories in one table and when you enter in the info for the sub catagories you just enter in the cat_id for the main catagory.

And when you run quries you just join by cat_id.

Ray

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.