Jump to content


Photo

WHERE statement question


  • Please log in to reply
2 replies to this topic

#1 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 18 May 2006 - 09:34 PM

Hi all

I 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 fields

job_title
reference
job_descriptions

What 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

if ($criteria != '')
{
    $sql = $sql." AND (jobs.job_title LIKE '%".$criteria."%' AND jobs.reference LIKE '%".$criteria."%' AND jobs.job_description LIKE '%".$criteria."%')";
}

Can anyone help me?

Thanks in advance

Dave

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 18 May 2006 - 09:47 PM

Just change AND to OR and it should work
if ($criteria != '')
{
    $sql = $sql." AND (jobs.job_title LIKE '%".$criteria."%' OR jobs.reference LIKE '%".$criteria."%' OR jobs.job_description LIKE '%".$criteria."%')";
}


#3 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 18 May 2006 - 09:57 PM

[!--quoteo(post=375069:date=May 18 2006, 04:47 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 18 2006, 04:47 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Just change AND to OR and it should work
if ($criteria != '')
{
    $sql = $sql." AND (jobs.job_title LIKE '%".$criteria."%' OR jobs.reference LIKE '%".$criteria."%' OR jobs.job_description LIKE '%".$criteria."%')";
}
[/quote]
star!

thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users