OVH Cloud OVH Cloud

moteur et array

2 réponses
Avatar
Andre Ebongue
salut les gars je susi en train d'essayer de mettre sur pied un petit moteur
de recherche pour ma db mais je piétine voici une partie de mon script.
if($rechercher && strlen(trim($motsclef)) > 0) // on vérifie presence d'un
mot clef
{
//config
$champs = array("Nom","Couleur","Région"); // champs dans lesquel on
recherche
$mode_defaut = "OR"; // mode de recherche OR ou AND, pour indiquer si on
fait un OU ou un ET des mots clefs
// formatage des mots clef
$motsclef = StripSlashes(trim($motsclef));
$motsclef = str_replace('\'', ' ', $motsclef);
$motsclef = str_replace(',', ' ', $motsclef);
$motsclef = str_replace(':', ' ', $motsclef);
$tab = explode(' ' , $motsclef);
$nb = count($tab);
// construction de la requete sql
$sql = "SELECT * FROM cantine";
$passage = 0;
while(list($motsclef) = each($motsclef))
{
if($passage) $sql .= " $mode_defaut "; else $sql .= " WHERE ";
$sql .= "(";
while(list($cle_champ,$champ) = each($champs))
{
if($cle_champ > 0) $sql .= " OR"; // si on est deja passe, on ajoute un
OR
$sql .= " $champ LIKE '%$motsclef%'";
}
$sql .= ")";
}
quand je le treste, j'ai ce type d'erreur:
Warning: Variable passed to each() is not an array or object in
c:\programmi\easyphp\www\vins\recherche.php on line 81
la ligne 81 serait celle ci:
while(list($motsclef) = each($motsclef))
et je ne comprend pas pourquoi. qui peut m'aider?
merci

2 réponses

Avatar
Guillaume JANY
Xref: tkmodapp cache:7984
X-TkModapp-Action: approve
Content-Transfer-Encoding: 8bit
Content-Type: text/plain;
charset="iso-8859-1"

$champs = array("Nom","Couleur","Région"); // champs dans lesquel on

...

while(list($cle_champ, [[[[[[[[[$champ]]]]]]]]] ) = each($champs))
{
if($cle_champ > 0) $sql .= " OR"; // si on est deja passe, on ajoute un
OR
$sql .= " [[[[[[[[[$champ]]]]]]]]] LIKE '%$motsclef%'";
}
$sql .= ")";
}
quand je le treste, j'ai ce type d'erreur:
Warning: Variable passed to each() is not an array or object in
c:programmieasyphpwwwvinsrecherche.php on line 81
la ligne 81 serait celle ci:
while(list($motsclef) = each($motsclef))
et je ne comprend pas pourquoi. qui peut m'aider?
merci


attention à ta variable '$champs'; tu oublies le 's'

Guillaume
www.designerspace.com

Avatar
Andre Ebongue
Merci à tous j'essaie et je vous fait savoir!