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
https://forums.phpfreaks.com/topic/47044-simple-select/
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
https://forums.phpfreaks.com/topic/47044-simple-select/#findComment-229422
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
https://forums.phpfreaks.com/topic/47044-simple-select/#findComment-229428
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.