trassalg Posted July 27, 2007 Share Posted July 27, 2007 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 https://forums.phpfreaks.com/topic/62099-solved-multiple-or-functions-within-a-select-command/ Share on other sites More sharing options...
Illusion Posted July 28, 2007 Share Posted July 28, 2007 The better way is use fulltext index on all the three columns and then make use of MATCH..........AGAINST. If u don't have any idea on Fulltext index refer to the MySQL manual. Link to comment https://forums.phpfreaks.com/topic/62099-solved-multiple-or-functions-within-a-select-command/#findComment-309461 Share on other sites More sharing options...
trassalg Posted July 28, 2007 Author Share Posted July 28, 2007 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 https://forums.phpfreaks.com/topic/62099-solved-multiple-or-functions-within-a-select-command/#findComment-309512 Share on other sites More sharing options...
trassalg Posted July 28, 2007 Author Share Posted July 28, 2007 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 https://forums.phpfreaks.com/topic/62099-solved-multiple-or-functions-within-a-select-command/#findComment-309538 Share on other sites More sharing options...
TD Posted July 30, 2007 Share Posted July 30, 2007 is it possible to do the same thing but with "AND" function? I tried but it just don't work ??? Link to comment https://forums.phpfreaks.com/topic/62099-solved-multiple-or-functions-within-a-select-command/#findComment-310838 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.