Eléphant du PHP |
167 Messages
15 mai 2013, 12:44
Le voici :
<?php
$where="";
if(isset($_POST['dpt']) and !empty($_POST['dpt'])){$where.="dpt = '".$_POST['dpt']."' and ";}
if(isset($_POST['nature']) and !empty($_POST['nature'])){$where.="nature = '".$_POST['nature']."' and ";}
if(isset($_POST['checkbox'])){$where.=implode($_POST['checkbox'])." and";}
if(isset($_POST['checkbox']) and !empty($_POST['checkbox'])){$where.="(dpt='".implode("' or dpt='",$_POST['checkbox'])."') and ";}
if(!empty($where)){$where = 'where '.substr($where, 0, -4);}
;
$sql="SELECT * from Etablissement $where order by nomEtablissement";
if(!$connexion->query($sql)) echo "Pb d'accès à la table Etablissement";
else{
echo "<table><tr><td>NOM D'ETABLISSEMENT</td></tr>";
foreach ($connexion->query($sql) as $row)
?>
<form action="" method="POST">
<p>Département</p>
<input type="checkbox" name="checkbox[]" value="75">75
<input type="checkbox" name="checkbox[]" value="92">92
<input type="checkbox" name="checkbox[]" value="95">95
<input type="checkbox" name="checkbox[]" value="98">98
<p>Nature</p>
<input type="radio" name="nature"value="1">Université
<input type="radio" name="nature" value="2">Ecole d'ingénieur
<input type="submit" value="Rechercher">
</form>
<?php
echo "<br><a href=\"etablissement1.php?idEtablissement=".$row['idEtablissement'].'">'.'<br/>'.$row['nomEtablissement'];
echo "</table>";
}
?>