Creating a search form with multiple checkboxes

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
iain
Forum Newbie
Posts: 4
Joined: Fri Aug 18, 2006 12:53 pm

Creating a search form with multiple checkboxes

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
iain
Forum Newbie
Posts: 4
Joined: Fri Aug 18, 2006 12:53 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply