Source : lesson_09_d4_departements.php |
Résultat |
<?php //Connexion à la base de données require ("../mysql_connexion/mysql_connexion.php"); $action_file = "show_solutions.php?exercise=lesson_09_d4_departements.php"; if (!isset($_POST['département_saisi'])) { echo "<table border=3 align=center > "; echo "<CAPTION align=top><p><h3> Trouvez un département ou son code</p>"; echo "<form action=$action_file method=post>"; echo "<tr><th>Début du nom ou du code du département : </th></tr>"; echo "<tr><td><input type=text size= 20 name='département_saisi'>"; echo "</td></tr>"; echo "<tr><td align=right height=30><input type=submit value='Envoyer'>"; echo "</table></body></html>"; } else { $dept = $_POST['département_saisi']; $sol=0; if (is_numeric($dept)) { echo "<br/><table border=2 align=center>"; echo "<tr><td>Le code choisi: </td><td>$dept</td></tr>"; $result = mysqli_query($mysqli,"select * from atelierphp_sol_departements_prefecture where departement_code like '$dept%' ") ; while ($row=mysqli_fetch_array($result)) { $sol++ ; echo "<tr><td>".$row['departement_nom']."</td>"; echo "<td>".$row['departement_code']."</td></tr>"; } echo "<td colspan=2 align=center> <a href=$action_file>Un autre ?</a></tr>"; echo "</table>"; } else { echo "<br/><table border=2 align=center>"; $result = mysqli_query($mysqli,"select * from atelierphp_sol_departements_prefecture where departement_nom like '$dept%' ") ; while ($row=mysqli_fetch_array($result)) { $sol++ ; echo "<tr><td>".$row['departement_nom']."</td>"; echo "<td>".$row['departement_code']."</td></tr>"; } echo "<td colspan=2 align=center> <a href=$action_file>Un autre ?</a></tr>"; echo "</table>"; } if ($sol==0) { echo "Département non trouvé, Saisie invalide ?"; } } ?>
|
Trouvez un département ou son code |