Jump to content


Dynamic creation of categories (MySQL/PHP)

  • Please log in to reply
2 replies to this topic

#1 slain84

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 04 August 2006 - 09:07 AM

Hi everyone,

I am going to program an ads page. Every ad belongs to a category. An example:

--> Cars --> Porsche --> Cayenne
--> DVDs --> Action-Movies --> >18 years --> Lethal Weapon 3

Thus, there might be several sub-categories. This is no problem at all, but these sub-categories should be created by the admin later dynamically. He should be able to click through the categories and add a sub-category to "Cayenne" for example.

I have now the problem that I do not really know how to set up the MySQL database and how a script should look like so that the added categories are displayed.

I was thinking about adding fields to the category table in the database. That means that cat01 stands for the first sub-category, cat02 for the second and so on. If the admin adds a new, a new cat03 must be created. I do not how to implement that in my PHP script though.

Can anyone help?



#2 manmadareddy

  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 04 August 2006 - 10:00 AM

you just need to have CategoryID,CategoryName,ParentID,Level,status
I hope these fields are sufficient.

#3 gerkintrigg

  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 04 August 2006 - 01:21 PM

yeah, provoded that you have parentID (as suggested above) you can state what level the category is at. If the parent id field is empty, your system can assume it's a top-level category and you can go from there.

Thanks for the suggestion... I think I'll do it that way too... ;o)
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users