Source : lesson_15_b_select_one_table.php |
Résultat |
<?php require ("../mysql_connexion/mysql_connexion.php"); //mysql_select_db($db) ; echo "<table><tr><td>"; $table_name = "atelierphp_sol_auteurs" ; read_table($table_name); echo "</td></tr></table>"; //read the table //---------------------------------------------------------------- function read_table($table_name) { global $mysqli; require_once("../mysql_connexion/mysql_connexion.php"); $j=0; //leture des noms de champs echo "<table border=1><tr>"; $result = mysqli_query($mysqli,"SHOW COLUMNS FROM ".$table_name.""); if (!$result) { echo 'Impossible exécuter la requête : '; exit; } if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { echo "<th>".$row['Field']."</th>"; } echo "</tr>"; } //lecture des données $result = mysqli_query($mysqli,"SELECT * FROM $table_name where auteur like 'J%' "); $fields = mysqli_num_fields($result); while ($row=mysqli_fetch_array($result)) { $j++; echo "<tr><td>$j</td>"; for($i=0;$i<$fields;$i++) { echo "<td>$row[$i]</td>"; } echo "</tr>"; } echo "</table>"; } ?>
|
CLE_AUTEUR | AUTEUR |
---|
1 | 4 | Jules Verne | 2 | 5 | Jean-Jacques Rousseau | 3 | 8 | Joanne Kathleen Rowling |
|
|