Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/projects/anton-quiz/setup/
create_admin.php
dbsetup.sql
drop_tables.php
install.php
show_tables.php
show_tables.php
59 lines UTF-8 Windows (CRLF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
// show all error reporting
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
ini_set('output_buffering', 0); // Do not buffer outputs, write directly
require __DIR__ . '/../dbconnect.php';
if ($conn->connect_errno) {
die("Misslyckades att ansluta till databasen: " . $conn->connect_error);
}
// Visa alla tabeller i databasen
$result = $conn->query("SHOW TABLES");
if ($result && $result->num_rows > 0) {
while ($row = $result->fetch_array()) {
$table = $row[0];
echo "<h2>Tabell: {$table}</h2>";
// Hämta allt innehåll från tabellen
$tableResult = $conn->query("SELECT * FROM `{$table}`");
if ($tableResult && $tableResult->num_rows > 0) {
// Hämta kolumninformation
$fields = $tableResult->fetch_fields();
// Börja bygga en HTML-tabell
echo "<table border='1' cellpadding='5' cellspacing='0'>";
// Skriv ut kolumnnamn som tabellhuvud (thead)
echo "<tr>";
foreach ($fields as $field) {
echo "<th>" . htmlspecialchars($field->name) . "</th>";
}
echo "</tr>";
// Hoppa tillbaka till början (ej alltid nödvändigt, men bra om man behöver läsa data igen)
$tableResult->data_seek(0);
// Iterera över alla rader och skriv ut data
while ($dataRow = $tableResult->fetch_assoc()) {
echo "<tr>";
foreach ($fields as $field) {
$colName = $field->name;
echo "<td>" . htmlspecialchars($dataRow[$colName]) . "</td>";
}
echo "</tr>";
}
echo "</table>";
} else {
echo "<p>Inga rader i denna tabell.</p>";
}
}
} else {
echo "<p>Inga tabeller hittades i databasen.</p>";
}