Page 1 of 1

searching

Posted: Thu Jul 29, 2004 2:56 am
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

Posted: Thu Jul 29, 2004 3:01 am
by feyd
it's often better to have a seperate table that can match them individually..

Posted: Thu Jul 29, 2004 3:04 am
by John Cartwright
sorry feyd.. can you be a bit more specific?

Posted: Thu Jul 29, 2004 3:14 am
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.

Posted: Thu Jul 29, 2004 3:16 am
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

Posted: Thu Jul 29, 2004 9:34 am
by Draco_03
Here's an exemple of a many-to-many relationships
Note that the students shcedule is a linking table

Posted: Thu Jul 29, 2004 12:36 pm
by McGruff