Page 1 of 1

Creating a search form with multiple checkboxes

Posted: Fri Aug 18, 2006 12:56 pm
by iain
Hi there,

I'm still getting to grips with coding, using PHP and mySQL, and wonder if anyone can help with something I'm trying to do.

At the moment I have...

a table Candidates :

CandidateID (primary key, autonumber)
FirstName
LastName
etc

A table Profiles :

ProfileID (primary key, autonumber)
Profile (text)

And an interlinking table CandidateProfiles :

CandidateID (integer)
ProfileID (integer)

So if the CandidateProfiles table looks like :

1, 2
1, 4
1, 6
2, 2
2, 5
2, 6
3, 1
3, 6
4, 2
4, 3
4, 5
4, 6

I'd want to have a search form with a checkbox for each Profile, and if checkboxes 2, 5, and 6 were checked to return a results page listing Candidates 2 and 4, because they have matching Profiles 2, 5 and 6.

Hope that makes sense and maybe someone can point me in the right diection with it...

Cheers,
Iain

Posted: Fri Aug 18, 2006 1:02 pm
by feyd
Looks like it'd be a SELECT on the Profiles table for the first listing. The search itself would be an INNER JOIN based SELECT linking the Profiles table to the Candidates table through your CandidatesProfiles table.

Posted: Fri Aug 18, 2006 1:28 pm
by iain
Cheers - I'm still a bit ropey on joins.

But with this, I think the main part I'm struggling with is how to record what checkboxes get checked in the checkbox, how to pass that to a results page, and compare those selected with the CandidateProfiles table.

But ultimately to have a search page like this.

Posted: Fri Aug 18, 2006 1:35 pm
by feyd
The general way checkboxes are passed is by naming them with a name that will automatically generate an array such as "foo[]" where each one has a value of an ID, let's say.