Jump to content

Archived

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

g23armani

Creating a simple(?) categorical system using PHP and MySQL

Recommended Posts

I'm working on a portion of my site that allows people to search through a series of articles. I want to sort the articles by category. The problem is, most articles can be placed into more than one category. For example, if I write an article: "Rock Climbing Techniques to Prevent Injury and Increase Strength" I would want this article to be coded under:

Rock Climbing
Injury Prevention
Strength Training

While I could manually place the article in each of it's categories, I'm sure there is a simple way to use PHP and MySQL to assign multiple categories to each article and then have these articles pulled if someone clicks on the appropriate category or searches for the right keyword.

If anyone knows of a good website, book, free code or script source etc that they could point me to that would be tremendously helpful.

Thanks!

Peter

Share this post


Link to post
Share on other sites
Whenever you have a situation like yours where

1 book can belong to many categories
1 category can contain many books

you have what is known as a "many-to-many" relationship.

To resolve this you create an intermediate link table "article_category", for instance.

Category
----------
1 | Rock Climbing
2 | Injury Prevention
3 | Strength Training

Article
-------------
1 | Rock Climbing Techniques to Prevent Injury and Increase Strength
2 | Climbing for Dummies


Article_category
---------------------
catid | articleid

1 | 1
2 | 1
3 | 1
1 | 2

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.