Esempio molto semplice:
<style>
table, td, th, tr {
border: 1px solid #000000;
}
</style>
<?php
// INSERISCI I DATI DI ACCESSO AL DATABASE E IL NOME DELLA TABELLA
$DB_SERVER = ""; //Server
$DB_USERNAME = ""; //Username
$DB_PASSWORD = ""; //Password
$DB_DATABASE = ""; //Database
$name_table = ""; //Nome tabella
$DB = mysqli_connect($DB_SERVER,$DB_USERNAME,$DB_PASSWORD,$DB_DATABASE);
$field = array();
$query = "DESCRIBE ".$name_table;
$result = $DB->query($query);
while ($resultarray=$result->fetch_assoc()) {
$field[] = $resultarray['Field'];
}
echo "<table>";
echo "<tr>";
foreach ($field as $thisfield) {
echo "<th>".$thisfield."</th>";
}
echo "</tr>";
$query = "SELECT * FROM ".$name_table;
$result = $DB->query($query);
while ($resultarray=$result->fetch_assoc()) {
echo "<tr>";
foreach ($field as $thisfield) {
echo "<td>".$resultarray[$thisfield]."</td>";
}
echo "</tr>";
}
echo "</table>";
$DB->close();
?>