[PHP4] Recherche sur deux mots
Bonjour,
J'ai cette petite requête pour faire une recherche qui fonctionne lorsque je recherche un seul mot mais pas si j'en rentre deux.
Est-ce que quelqu'un peut m'aider ? Cela vient-il de la gestion du mot trop court ?
Merci
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
//MOT_COURT = gérer mot trop court
define("MOT_COURT", 1);
$keys = explode(" ", $search);
$andOr = "and"; // ou "or" selon un test, une préférence....
$sql_val = "select * from produits where ";
$max = count($keys) - 1;
$and = false;
for ($i = 0; $i < $max; $i++)
{
if (strlen($keys[$i]) > MOT_COURT)
{
$and = true;
$sql_val .= "(Nom2 like \"$keys[$i]%\") $andOr ";
//$sql_val .= "$andOr";
}
}
if (strlen($keys[$i]) > MOT_COURT)
{
$and = true;
$sql_val .= "(Nom2 like \"$keys[$i]%\")";
} |