Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/9953-where-statement-question/
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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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