Jump to content

[SOLVED] Multiple "OR" functions within a SELECT command


trassalg

Recommended Posts

How would I modify the following so it enables me to search any or all of the 3 "search" fields?

 

$query = "SELECT * FROM articleTable WHERE (articleTitle LIKE '$srch1' OR articleText LIKE '$srch1') AND (dateOfArticle BETWEEN '$fromDate' AND '$untilDate')";

 

This code is working, but I would like to add the possibility to search "$srch2" and "$srch3" in both columns "articleTitle" and "articleText" but without the obligation that they be filled in.

 

I've tried the following, but it doesn't seem to work:

 

$query = "SELECT * FROM articleTable WHERE ((articleTitle LIKE '$srch1' OR '$srch2' OR '$srch3') OR (articleText LIKE '$srch1' OR '$srch2' OR '$srch3')) AND (dateOfArticle BETWEEN '$fromDate' AND '$untilDate')";

 

Any ideas?

Link to comment
Share on other sites

From what I read, the Fulltext indexing comes with a lot of problems.  For me, namely because I want to allow partial string searches (i.e. ability to look for "%put%" and come with results that include "computer" and "putting".  Any ideas why the current version I have posted isn't allowing all fields to be checked?

 

Is there a way to allow multiple individual strings be searched in the same field of a form, rather than requiring various fields??

Link to comment
Share on other sites

Figured it out.

 

Added a default value of "" to each form field.

 

MySQL query is:

$query = "SELECT * 
FROM articleTable 
WHERE ((articleTitle LIKE \"%$search1%\" 
OR articleText LIKE \"%$search1%\" 
OR articleTitle LIKE \"%$search2%\" 
OR articleText LIKE \"%$search2%\" 
OR articleTitle LIKE \"%$search3%\" 
OR articleText LIKE \"%$search3%\")) 
AND dateOfArticle 
BETWEEN '$fromDate' AND '$untilDate'";

 

And before the SQL query, the following:

if ($search1 == "") {
$search1 = "Text_String_That_Will_Never_Be_Found";
}
if ($search2 == "") {
$search2 = "Text_String_That_Will_Never_Be_Found";
}
if ($search3 == "") {
$search3 = "Text_String_That_Will_Never_Be_Found";
}

Link to comment
Share on other sites

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.