Zobrazenie všetkých stĺpcov z MYSQL cez PHP a html
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<?php
$servername = "mysql-server";
$username = "meno";
$password = "heslo";
$dbname = "tabulka";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id,username, value, starts, expire, tukeid FROM real_radcheck";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>id</th><th>tukeid</th><th>username</th><th>value</th><th>starts</th><th>expire</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"]. "</td><td>" . $row["tukeid"]. "</td><td>" . $row["username"]. " </td><td>" . $row["value"]. "</td><td>". $row["starts"]. "</td><td>". $row["expire"]. "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
(P) Martin Hasin
10.1.2020
</body>
</html>
Do hlavičky je potrebné doplniť kódovanie pre výstupný HTML.
Hlavne preto, aby sa správne zobrazovala diakritika.
!!! POZOR EŠTE NA UKLADANIE EDITORA PHP SKRIPTU !!!
napr. vo WinSCP to treba nastaviť z 1250 na UTF-8
table, th, td {
border: 1px solid black;
}