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
| <?php
if((isset($_POST['RechercherArticle'])) && (!empty($_POST['Titre']) || !empty($_POST['Categorie']) || !empty($_POST['Periode']) || !empty($_POST['Sexe']) || !empty($_POST['Age']) || !empty($_POST['Licence'])))
{
$sql = "SELECT membre.id_membre, article.id_article, titre_article, SUBSTR(contenu_article, 0, 400) AS contenu,
parution_article, vignette_article, pseudo_membre, COALESCE(com.nbcommentaire, 0) AS nbcom, COALESCE(note.nbavis, 0) AS nbav
FROM article
JOIN membre ON membre.id_membre = article.id_membre
LEFT OUTER JOIN(
SELECT COUNT(*) AS nbcommentaire, id_article FROM commentaire GROUP BY id_article
) AS com
ON com.id_article = article.id_article
LEFT OUTER JOIN(
SELECT COUNT(*) AS nbavis, id_article FROM note_article GROUP BY id_article
) AS note
ON note.id_article = article.id_article
WHERE ";
if(!empty($_POST['Titre']) || !empty($_POST['Categorie']) || !empty($_POST['Periode']) || !empty($_POST['Sexe']) || !empty($_POST['Age']) || !empty($_POST['Licence']))
{
if(!empty($_POST['Titre'])){ $sql .= "to_tsvector('french', titre_article) @@ to_tsquery('french', '".SecuBDD($_POST['Titre'])."')"; }
if(!empty($_POST['Categorie'])){ $sql .= "categorie_article = ".SecuBDD($_POST['Categorie'])." AND "; }
if(!empty($_POST['Periode'])){ $sql .= "periode_article = ".SecuBDD($_POST['Periode'])." AND "; }
if(!empty($_POST['Sexe'])){ $sql .= "sexe_article = ".SecuBDD($_POST['Sexe'])." AND "; }
if(!empty($_POST['tranche_age_article'])){ $sql .= "sexe_article = ".SecuBDD($_POST['Age'])." AND "; }
if(!empty($_POST['Licence'])){ $sql .= "licence_article = ".SecuBDD($_POST['Licence'])." AND "; }
$sql = substr($sql, 0, -5);
// $RechercheArticle = pg_query($sql);
echo $sql;
}
} |
Partager