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?

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??

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";
}

Archived

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

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