CanMan2004 Posted May 18, 2006 Share Posted May 18, 2006 Hi allI have a form which has an input box called "criteria" when the form is submitted, a query is processed, part of this query is a WHERE statement which looks in 3 fields in the database to see if the value which was entered into the "criteria" input box exists.At the moment the query checks to see of the value entered is contained in the following db fieldsjob_titlereferencejob_descriptionsWhat I want to do is get it to check if it exists in any of them and not all of them, it used to be that whatever was typed in the "criteria" box had to exist in those 3 fields in the db, now it only needs to appear in either of the 3 fields and not all of them.The query is split into many parts as there is quite a complex search system attached, but I cannot seem to get the part ive talked about working, the part of the code which does this WHERE stament is[code]if ($criteria != ''){ $sql = $sql." AND (jobs.job_title LIKE '%".$criteria."%' AND jobs.reference LIKE '%".$criteria."%' AND jobs.job_description LIKE '%".$criteria."%')";}[/code]Can anyone help me?Thanks in advanceDave Quote Link to comment https://forums.phpfreaks.com/topic/9953-where-statement-question/ Share on other sites More sharing options...
alpine Posted May 18, 2006 Share Posted May 18, 2006 Just change AND to OR and it should work[code]if ($criteria != ''){ $sql = $sql." AND (jobs.job_title LIKE '%".$criteria."%' OR jobs.reference LIKE '%".$criteria."%' OR jobs.job_description LIKE '%".$criteria."%')";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9953-where-statement-question/#findComment-37009 Share on other sites More sharing options...
CanMan2004 Posted May 18, 2006 Author Share Posted May 18, 2006 [!--quoteo(post=375069:date=May 18 2006, 04:47 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 18 2006, 04:47 PM) [snapback]375069[/snapback][/div][div class=\'quotemain\'][!--quotec--]Just change AND to OR and it should work[code]if ($criteria != ''){ $sql = $sql." AND (jobs.job_title LIKE '%".$criteria."%' OR jobs.reference LIKE '%".$criteria."%' OR jobs.job_description LIKE '%".$criteria."%')";}[/code][/quote]star!thanks Quote Link to comment https://forums.phpfreaks.com/topic/9953-where-statement-question/#findComment-37012 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.