1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
function recherche(){
$fichier = '../document/chaussures.xml';
$xml = simplexml_load_file($fichier);
$toParse = $xml->chaussures;
if (isset ($_POST[''])){
$recherche=$_POST['recherche'];
}
if(isset($_POST['choix'])){
$choix=$_POST['choix'];
echo "<h4>Vous avez fait une recherche par : ".$choix."</h4>";
}
if(file_exists($fichier) && !empty($recherche)){
foreach($xml as $item){
$tableau = array(
"code" => $item->code,
"type"=>$item->type,
"nom" =>$item->nom,
"couleur" => $item -> couleur,
);
switch ($choix) {
case 'code':
if(strstr(strtolower($tableau["code"]),strtolower($recherche))){
echo '<p><a href="resultat.php?code='.$tableau["code"].'">'.$tableau["nom"].' - '.$tableau["type"].'</a></p>';
}
break;
case 'type':
if(strstr(strtolower($tableau["type"]),strtolower($recherche))){
echo '<p><a href="resultat.php?code='.$tableau["code"].'">'.$tableau["nom"].' - '.$tableau["type"].'</a></p>';
}
break;
case 'couleur':
if(strstr(strtolower($tableau["couleur"]),strtolower($recherche))){
echo '<p><a href="resultat.php?code='.$tableau["code"].'">'.$tableau["nom"].' - '.$tableau["type"].'</a></p>';
}
break;
default:
if(strstr(strtolower($tableau["nom"]),strtolower($recherche))) {
echo '<p><a href="resultat.php?code='.$tableau["code"].'">'.$tableau["nom"].' - '.$tableau["type"].'</a></p>';
}
break;
}
}
}
} |
Partager