Jump to content


Photo

Categories with PHP


  • Please log in to reply
2 replies to this topic

#1 chrziz

chrziz
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 13 April 2006 - 06:59 PM

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?

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 13 April 2006 - 07:53 PM

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


#3 chrziz

chrziz
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 13 April 2006 - 11:47 PM

Ok, thanks a lot!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users