searching

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

searching

Post by John Cartwright »

K I'm building a template system for my comany and I want a customer to be able to click on a catagory and have all the templates in that catagory be displayed.

The problem is a template can be in several catagories.

What do you guys think I should to with my DB.

Should I do

catagories table

catagory | templateids
gaming | 2, 25, 42, 13

or should i do

templates table

templateid | catagories
2 | gaming, flash intro



Also anyone have any idea how I would compare the results?




I have a fair grip on this but just wondering if anyone could throw me some useful advice :)
templateid | catagories
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's often better to have a seperate table that can match them individually..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

sorry feyd.. can you be a bit more specific?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sure..

your relationship implies, and even illustrates, a many-to-many relationship. Those are better served by a seperate table for the linkage between them.

so you would want a table that is like:

template_id
category_id

each record holds only 1 id for each side. They aren't unique keys, as then you'd have an asymetric one-to-many system.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Thanks a lot Feyd.


*mental note* make sure feyd doesnt use big words at 4:15 in the morning.


:) :) took me like 4 reads to understand what you were saying

Thanks agian Feyd
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Here's an exemple of a many-to-many relationships
Note that the students shcedule is a linking table
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Post Reply