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
| public function searchAndDisplay($ingredients){
$result = array();
$listeIngredients = explode('-', $ingredients);
$nbrIngredients = sizeof($listeIngredients);
$requete = 'SELECT * FROM recette WHERE titre LIKE "%'.$listeIngredients[0].'%"';
for($i = 1; $i < $nbrIngredients; $i++){
if($listeIngredients[$i] != null){
$requete .= ' OR titre LIKE "%'.$listeIngredients[$i].'%"';
}
}
$query = $this->pdo->prepare($requete);
$query->execute();
if($row = $query->fetch(PDO::FETCH_OBJ)){
while($row){
$result[] = new Recette($row->id, $row->titre, $row->nbpersonnes, $row->dureepreparation, $row->dureeattente,
$row->dureecuisson, $row->difficulte, $row->note, $row->prix, $row->ingredients,
$row->preparation, $row->conseil, $row->timestamp, $row->date,
$row->image, $row->description, $row->validation, $row->idutilisateur);
}
return $result;
} else{ /* [....] Encore du code etc.. */. |
Partager