<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="author" content="Manuele" />
<title> Connexion BdD</title>
<link rel="stylesheet" href="css/tableaux.css" />
</head>
<body>
<h1>Liste de clients </h1>
<?php
/* on etablit la connexion */
require "connexion.php" ;
$mysqli = connexion();
$sql = "SELECT id, nom, email, adresse FROM client ORDER BY nom " ;
?>
<h2> Requête avec un tableau à indice </h2>
<?php
$result = $mysqli->query ($sql) ;
if ( ! $result ) { echo "<p> Desolée, requête impossible ! </p>" ; }
else {
echo "<table> <caption> Clients </caption>";
echo "<tr> <th> id </th> <th> Nom </th>
<th> Email </th> <th> Adresse </th> </tr>";
/* on va recuperer ligne a ligne avec une boucle */
/* cette fois, nous allons utiliser un tableau a indice */
while ($ligne = $result->fetch_row() ) {
echo " <tr> ";
echo "<td>" . $ligne[0] . "</td>";
echo "<td>" . $ligne[1] . "</td>";
echo "<td>" . $ligne[2] . "</td>";
echo "<td>" . $ligne[3] . "</td>";
echo "</tr> ";
}
echo "</table>";
}
?>
<h2> Requête avec un tableau associatif : </h2>
<?php
$result = $mysqli->query ($sql) ;
if ( ! $result ) { echo "<p> Desolée, requête impossible ! </p>" ; }
else {
echo "<table> <caption> Clients </caption>";
echo "<tr> <th> id </th> <th> Nom </th>
<th> Email </th> <th> Adresse </th> </tr>";
/* on va recuperer ligne a ligne avec une boucle */
/* cette fois, nous allons utiliser un tableau a indice */
while ($ligne = $result->fetch_assoc() ) {
echo " <tr> ";
echo "<td>" . $ligne['id'] . "</td>";
echo "<td>" . $ligne['nom'] . "</td>";
echo "<td>" . $ligne['email'] . "</td>";
echo "<td>" . $ligne['adresse'] . "</td>";
echo "</tr> ";
}
echo "</table>";
}
$mysqli->close();
?>
</body>
</html>