Skip to content
Snippets Groups Projects
Commit 098e5059 authored by suprasanity's avatar suprasanity
Browse files
parents 7df96309 0186874f
No related branches found
No related tags found
No related merge requests found
...@@ -217,21 +217,22 @@ function getRecettes($search=""){ ...@@ -217,21 +217,22 @@ function getRecettes($search=""){
// https://stackoverflow.com/a/18603279 // https://stackoverflow.com/a/18603279
$categoryId = $search["categoryId"] ?? ""; $categoryId = $search["categoryId"] ?? "";
$name = $search["name"] ?? ""; $name = $search["name"] ?? "";
$ingredientId = $search["ingredientId"] ?? ""; $ingredients = $search["ingredients"] ?? "";
$difficulte = $search["difficulte"] ?? ""; $difficulte = $search["difficulte"] ?? "";
$tempsPreparation = $search["tempsPreparation"] ?? ""; $tempsPreparation = $search["tempsPreparation"] ?? "";
$auteurId = $search["auteurId"] ?? ""; $auteurId = $search["auteurId"] ?? "";
// On construit la requête // On construit la requête
$queryString = "SELECT * FROM m_recette WHERE 1=1"; $queryString = "SELECT * FROM m_recette INNER JOIN m_recetteIngredient ON m_recette.id=m_recetteIngredient.recetteId WHERE 1=1";
if(!empty($categoryId)){ if(!empty($categoryId)){
$queryString .= " AND categoryId=:categoryId"; $queryString .= " AND categoryId=:categoryId";
} }
if(!empty($name)){ if(!empty($name)){
$queryString .= " AND nom LIKE :name"; $queryString .= " AND nom LIKE :name";
} }
if(!empty($ingredientId)){ if(!empty($ingredients)){
$queryString .= " AND ingredientId=:ingredientId"; $ingredientsIn = implode(',', $ingredients);
$queryString .= " AND ingredientId IN (:ingredients)";
} }
if(!empty($difficulte)){ if(!empty($difficulte)){
$queryString .= " AND difficulte=:difficulte"; $queryString .= " AND difficulte=:difficulte";
...@@ -254,7 +255,7 @@ function getRecettes($search=""){ ...@@ -254,7 +255,7 @@ function getRecettes($search=""){
$query->bindParam(':name', $name); $query->bindParam(':name', $name);
} }
if(!empty($ingredientId)){ if(!empty($ingredientId)){
$query->bindParam(':ingredientId', $ingredientId); $query->bindParam(':ingredients', $ingredientsIn);
} }
if(!empty($difficulte)){ if(!empty($difficulte)){
$query->bindParam(':difficulte', $difficulte); $query->bindParam(':difficulte', $difficulte);
...@@ -432,7 +433,7 @@ function getIngredients($recetteId=""){ ...@@ -432,7 +433,7 @@ function getIngredients($recetteId=""){
$query->execute(); $query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC); return $query->fetchAll(PDO::FETCH_ASSOC);
}else{ }else{
$query = Connexion::pdo()->prepare("SELECT * FROM m_ingredient WHERE id IN (SELECT ingredientId FROM m_ingredientRecette WHERE recetteId=:recetteId) ORDER BY nom"); $query = Connexion::pdo()->prepare("SELECT * FROM m_ingredient WHERE id IN (SELECT ingredientId FROM m_recetteIngredient WHERE recetteId=:recetteId) ORDER BY nom");
$query->bindParam(':recetteId', $recetteId); $query->bindParam(':recetteId', $recetteId);
$query->execute(); $query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC); return $query->fetchAll(PDO::FETCH_ASSOC);
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
<!-- Recettes --> <!-- Recettes -->
<div class="container"> <div class="container">
<div class="filtreRecettes bg-light my-5"> <div class="filtreRecettes p-2 bg-light my-5">
<h5>Filtre</h5> <h5><strong>Filtre</strong></h5>
<div class="row"> <div class="row">
<div class="col-sm"> <div class="col-sm">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment