Källkod
Följande filer och mappar finns under mappen webbserverprogrammering.
Mappar visas till vänster och filer till höger. Klicka på en fil eller mapp för att öppna nedan eller visa dess innehåll.
webbserverprogrammering/exercises/mysql/exercise_1/
10 filer
back_button.php
create_table.php
dbconnection.php
delete_row.php
delete_table.php
index.php
insert_default_values.php
insert_values.php
print_table.php
update_values.php
create_table.php
dbconnection.php
delete_row.php
delete_table.php
index.php
insert_default_values.php
insert_values.php
print_table.php
update_values.php
print_table.php
51 lines ASCII Windows (CRLF)
<!DOCTYPE html>
<html lang="sv">
<head>
<title>Skriv ut tabell</title>
<meta charset="utf-8">
<style type="text/css">
table#data {
border-collapse: collapse;
}
#data td {
padding: 8px;
border: 1px solid #686868;
}
</style>
</head>
<body>
<?php
include('back_button.php');
include ('dbconnection.php');
try {
/*** The SQL SELECT statement ***/
$sql = "SELECT * FROM kompisar";
$stmt = $dbconn->prepare($sql);
// fetch width column names, create a table
$data = [];
$stmt->execute($data);
$output = "<table id='data'><caption><strong>Kompisar</strong></caption><br><br>";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$output .= "<tr>".
"<td>".htmlentities($res['firstname'])."</td>".
"<td>".htmlentities($res['lastname'])."</td>".
"<td>".htmlentities($res['mobile'])."</td>".
"<td>".htmlentities($res['email'])."</td>".
"</tr>";
}
$output .= "</table>";
echo "$output";
}
catch(PDOException $e)
{
echo $sql . "<br />" . $e->getMessage();
}
$dbconn = null;
?>
</body>
</html>