j'ai fais un script de recherche sur plusieurs tables sur plusieurs champs, ça fonctionne mais je voudrais simplifier la requête sql qui n'est pas très ergonomique en lecture.
Je sais qu'il y a quelque comme ça :
<?php If(!empty($_POST['region']){
$sql .= 'and idregion='.$idregion;
} ?> mais je n'arrive pas à l'adapter à mon script écrit avec mysqli
Merci de vos suggestions ...
<?php if(empty($_POST['region'])) {
echo'<br /><font color="red">Merci de choisir une région !</font><br /><br />';
}
elseif(empty($_POST['departement']) && empty($_POST['ville'])) {
$sql = mysqli_query($bdd, "SELECT * FROM membre, region, departement, ville WHERE membre.id_departement=departement.id_departement and region.id_region=departement.id_region and membre.id_ville=ville.id_ville and membre.valide=1 and membre.id_region='".$_POST['region']."' and sexe='".$_POST['sexe']."' ORDER BY id DESC")or die(mysqli_error($bdd));
}
elseif(empty($_POST['ville'])) {
$sql = mysqli_query($bdd, "SELECT * FROM membre, region, departement, ville WHERE membre.id_departement=departement.id_departement and region.id_region=departement.id_region and membre.id_ville=ville.id_ville and membre.valide=1 and membre.id_departement='".$_POST['departement']."' and sexe='".$_POST['sexe']."' ORDER BY id DESC")or die(mysqli_error($bdd));
}
else {
$sql = mysqli_query($bdd, "SELECT * FROM membre, region, departement, ville WHERE membre.id_departement=departement.id_departement and region.id_region=departement.id_region and membre.id_ville=ville.id_ville and membre.valide=1 and membre.id_departement='".$_POST['departement']."' and membre.id_ville='".$_POST['ville']."' and sexe='".$_POST['sexe']."' ORDER BY id DESC")or die(mysqli_error($bdd));
} ?>