Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/sql-intro/sql-intro1/
createtable.php
insertpost.php
skrivut.php
sql-intro1-index.php
tabort.php
uppdatera.php
skrivut.php
52 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
echo "<table style='border: solid 1px black;'>";
echo "<tr><th>Id</th><th>Firstname</th><th>Lastname</th></tr>";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current(): string {
return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren(): void {
echo "<tr>";
}
function endChildren(): void {
echo "</tr>" . "\n";
}
}
include ('../../../dbconnection.php');
try {
$stmt = $dbconn->prepare("SELECT id, förnamn, efternamn, mobil, epost FROM kompisar");
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error:" . $e->getMessage();
}
$dbconn = null;
?>
</body>
</html>