Jump to content

Recommended Posts

I'm putting together a form that will allow users to pare down a list of users based on their criteria. This has to be boolean, though, and I'm having a hard time logically putting it together. The form looks like this:

 

User Hair Color

<select>

Brown

</select>

<select>

Blonde

</select>

<checkbox>AND</checkbox><checkbox>OR</checkbox>

 

 

User Eye

<select>

Blue

</select>

<select>

Hazel

</select>

<checkbox>AND</checkbox><checkbox>OR</checkbox>

 

 

User Height

<select>

Short

</select>

<select>

Tall

</select>

<checkbox>AND</checkbox><checkbox>OR</checkbox>

 

So ultimately a person could have selected that they want to see a list of users that have:

Brown Hair OR Blonde Hair AND Blue Eyes OR Tall OR Short

 

Is there an easy way to do this? Obviously these aren't the real criteria. So basically, I've got 5 sections, all of which contain 5 select boxes with possible criteria. Each of these criteria has an AND/OR next to it. Between each section is another AND/OR set of checkboxes. So within each section you've got AND/OR and then between sections there's an AND/OR. The data is stored in the database like this:

 

userHairColorItems

userID = 1

hairColorID = 2

 

userHeightItems

userID = 1

userHeightID = 1

 

Where hairColorID = 2 would be Blonde, userHeightID = 1 would be short, etc.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/63577-boolean-criteria-search/
Share on other sites

You could have, for this

 

Brown Hair OR Blonde Hair AND Blue Eyes OR Tall OR Short

 

WHERE ( (HairColorID = 1) OR (HairColorID = 2)) 
AND (eyeColor = 1) 
AND ((userHeightID = 1) OR (userHeightID = 2))

 

but it's easier to use the IN syntax instead of multiple ORs

 

WHERE ( HairColorID IN (1,2) ) 
AND ( eyeColor = 1 ) 
AND ( userHeightID IN (1,2) )

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.