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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.