| Jamal Dayes 2006-02-12, 6:43 pm |
| Hi, I have a query and a results page that i want to use to allow users to
search for CD's by subject type. The Relationship is M:N because One CD can
have many different subject types and one subject can below to many different
CD's
I have 3 tables set up as follows:
CDtable:
cdName
cdId
SubjectTable:
subName
subId
Relationship
subId
cdId
The query page dynamically produces the checkboxes in a list as pulled
directly from the subjectTable. this is so that the end user can add more
subject types to the table and they will automatically update the checkbox
list.
What I need to do is produce a query that will take the selected checkboxes
and match them against the relationship table to produce a list of all the CD's
that match "ANY" of the subject types that were searched.
This query has been racking my brains. Firstly because I assume I have to take
the checkbox data and covert it in a string as the field type is the same for
each subject type.
if(is_array($_POST))
$_POST=implode(",",$_POST);
something like this would do the trick.
I'm just finding it impossible to get the query right?
SELECT CDtable.cdName, SubjectTable.subjectName, Relationship * FROM CDtable,
SubjectTable, Relationship WHERE IN ('%%%s%%') ORDER BY CdName
%%%%s%% - being my form posted variable.
This is doing my head in just thinking about. Can anyone point me in the right
direction or tell me where i'm going wrong.
Kind Regards
|