0

I need to be able to search and to consider the different words as keywords instead of a string.

Actually, if I search "lamp blue", a result of "blue and white lamp" or "blue lamp" will not show up. I want to consider spaces as keywords separator. How can we do this simply considering my actual code ?

$pdo2_where = " WHERE (" .$db_type_1_associations['nom_bot'] ." LIKE ? || " .$db_type_1_associations['id'] ." LIKE ? || " .$db_type_1_associations['nom_fr'] ." LIKE ? || " .$db_type_1_associations['description'] ." LIKE ? || " .$db_type_1_associations['commentaire_public'] ." LIKE ?)" .$pdo2_add_where_photos ;
$pdo2_execute = array (
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%'
); 

*also it could be good to separate slashes, commas and other classic separators.

1
  • A little noobish maybe, but query string explode, count loop? Don't be a hater :-)
    – Insyte
    Jan 14, 2013 at 22:07

1 Answer 1

1

This is a good time to be thinking about using a search engine. Or if possible, at least full text indexes.

You can do this with just SQL, but your query is going to get more complex. You will need to split your search string on spaces and add additional or clauses for each keyword and field combination.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.