marcs910 Posted April 14, 2007 Share Posted April 14, 2007 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 " Quote Link to comment https://forums.phpfreaks.com/topic/47044-simple-select/ Share on other sites More sharing options...
bubblegum.anarchy Posted April 14, 2007 Share Posted April 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/47044-simple-select/#findComment-229422 Share on other sites More sharing options...
marcs910 Posted April 14, 2007 Author Share Posted April 14, 2007 But will this work if more than one condition is true? Quote Link to comment https://forums.phpfreaks.com/topic/47044-simple-select/#findComment-229425 Share on other sites More sharing options...
bubblegum.anarchy Posted April 14, 2007 Share Posted April 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/47044-simple-select/#findComment-229428 Share on other sites More sharing options...
marcs910 Posted April 14, 2007 Author Share Posted April 14, 2007 Thanks but I know basic conditional logic. Before I posted I had tried it with OR then AND with no luck on what I was looking for. I'll keep searching for the right answer here in the forums. I appreciate the words. Quote Link to comment https://forums.phpfreaks.com/topic/47044-simple-select/#findComment-229430 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.