Hi guys, I am trying to build some kind of "advanced" search engine for my website. Not like google of course, but just advanced enough to have some of google's features.
What I mean by this is I want to enable multiple keyword search, and also if possible to display results based on appearances. And another thing I was looking forward was the typical "Myabe you meant to say..."
Ok, so my actual code is this:
This code works perfectly, so dont worry if you see something missing, I just copied and pasted it and I may have left out some } or whatever...
And after all this I run the query and get the result, and I display the results.
If anyone knows how to add to this, or modify to make it faster/better please feel free to post!
Thanks alot
EDIT:
All the latin1 and COLLATE and stuff dont worry about it, is just that my site is in spanish and I dont want mysql filled with errors because of special characters...
What I mean by this is I want to enable multiple keyword search, and also if possible to display results based on appearances. And another thing I was looking forward was the typical "Myabe you meant to say..."
Ok, so my actual code is this:
| Code: |
| $suser = strtolower(trim($_GET['suser']));
if(!get_magic_quotes_gpc()) { $suser = addslashes($suser); } $keyword = $suser; if($keyword == '%'){ echo 'Falló la búsqueda...'; return; } $search = preg_replace('/\s+/', ' ', $keyword); $keywords = explode(" ", $search); $keywords = array_diff($keywords, array("")); //Set the MySQL query if ($search == NULL or $search == '%'){ } else { global $database; for ($i=0; $i<count($keywords); $i++) { $query = "SELECT * FROM `users` " . 'WHERE `username` LIKE CONVERT(_utf8 \'%'.$keywords[$i].'%\' USING latin1) COLLATE latin1_spanish_ci'. ' OR `email` LIKE CONVERT(_utf8 \'%'.$keywords[$i].'%\' USING latin1) COLLATE latin1_spanish_ci' . ' OR `name` LIKE CONVERT(_utf8 \'%'.$keywords[$i].'%\' USING latin1) COLLATE latin1_spanish_ci' . ' OR `last_name` LIKE CONVERT(_utf8 \'%'.$keywords[$i].'%\' USING latin1) COLLATE latin1_spanish_ci' . ' ORDER BY `username`'; } } |
This code works perfectly, so dont worry if you see something missing, I just copied and pasted it and I may have left out some } or whatever...
And after all this I run the query and get the result, and I display the results.
If anyone knows how to add to this, or modify to make it faster/better please feel free to post!
Thanks alot
EDIT:
All the latin1 and COLLATE and stuff dont worry about it, is just that my site is in spanish and I dont want mysql filled with errors because of special characters...
