Jump to content

Categories with PHP


chrziz

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?
Link to comment
https://forums.phpfreaks.com/topic/7337-categories-with-php/
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
Link to comment
https://forums.phpfreaks.com/topic/7337-categories-with-php/#findComment-26718
Share on other sites

Archived

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

×
×
  • Create New...

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.