Jump to content

Simple select


marcs910

Recommended Posts

I have 5 fields in a form. I want to be able to search those fields in a db wheter I have a value in 1 field or if I have a value in 5 fields.

The way i have it now I know it selects a row if all values are filled in. What I do want it to do is select if I have "stories = 2 and bedroom = 3" or whatever.

 

I hope you halfway understand.

 

"SELECT * FROM homes WHERE stories = '$st' AND bedroom = '$br' AND bathroom = '$btr' AND zip = '$zip' AND location = '$loc' ORDER BY zip ASC "
Link to comment
Share on other sites

Concatinating all the conditions with AND means that all conditions must be TRUE for the record to be returned, use OR instead to return the records where only one condition is TRUE...

 

WHERE first = '1st' AND second = '2nd' AND third = '4rd' => WHERE TRUE AND TRUE AND FALSE => will not return the record because not all conditions are TRUE on the other hand..

WHERE first = '2st' OR second = '1nd' OR third = '3rd' => WHERE FALSE OR FALSE OR FALSE => will return the record because at least one of the conditions is TRUE.

 

 

 

Link to comment
Share on other sites

WHERE TRUE OR TRUE OR TRUE => will return TRUE

WHERE TRUE OR TRUE OR FALSE => will return TRUE

WHERE TRUE OR FALSE OR FALSE => will return TRUE

and even

WHERE FALSE OR FALSE OR TRUE => will return TRUE

 

hence... the return value will be TRUE when at least one of the conditions is TRUE

 

Consider reading up on basic conditional logic.

Link to comment
Share on other sites

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.