Re: [PHP] Categories like wordpress
[email protected] (Brady Mitchell)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
On May 1, 2008, at 743AM, Richard Heyes wrote: >> Is this how its done or am I barking up the wrong tree? > > You have multiple options: > > 1. Fully normalised, where you have three tables - one for your > "articles", one for your categories and a link table. This is the route that I would suggest, it's the most flexible and fastest to query. Just to expound a little... images table: - image_id - image_filename category table - category_id - category_name image_category_mapping table: - image_id - category_id Then when you want to get all of the images for a category: SELECT image_id, image_filename FROM images JOIN image_category_mapping ON images.image_id = image_category_mapping.image_id WHERE category_id = 10; Getting all the categories an image is in: SELECT category_id FROM image_category_mapping WHERE image_id = 42; It seems like more work than the route you described, but it's way more flexible, and as Richard pointed out, it's fully normalized. Brady