Jump to content

Archived

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

CanMan2004

WHERE statement question

Recommended Posts

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

[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 advance

Dave

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites

×

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.