I'm trying to write my own forums (yes, I know there are loads out there for free, but this is more to learn how and see if I can than to have a forum) 🙂 and I've come to a bit of a wall as far as a search function. I've searched the forums, but it gets somewhat difficult to search a forum for how to search in a forum 😛
The problem is that I have multiple search options ie: search for multiple keywords in author, subject, body; search by date range; AND vs. OR etc. The only was I have been able to figure this out is to use massive nested if statements.
//$Keywords="multiple keywords separated by spaces";
$Keywords=explode(" ",$Keywords);
if($SearchField=="Author")
{
if($SearchLogic=="Or")
{
for(int $i=0; $i<(count($Keywords-1)); $i++)
{
$result[$i]=mysql_query("SELECT * FROM posts WHERE Author LIKE '%$Keywords[$i]%'");
$Data[$i]=mysql_fetch_assoc($result[$i]);
}
}
}
and repeat this for each of the possible search combinations.
(I'm thinking the easiest thing to do is to get all results and then process the date range separately, since each $Data element contains the date)
While this method will certainly work, I can't help but think that there must be a better way. I'm somewhat new to PHP/mySQL (although I have experience in other programming languages) any help anyone could offer would be greatly appreciated 🙂
-Chris
(incedentally, would it be to my advantage to download phpbb, and take a look at their search algorithm, or would this just confuse the matter? (assuming it's not copyright violation to steal their algorithm 😃 ))