Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/databaser/databaser3/
car.php
createtables.php
databaser3.php
databaser3a.php
databaser3b.php
databaser3c.php
databaser3d.php
databaser3e.php
deletetables.php
garage.php
owner.php
start.php
databaser3d.php
125 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bilar</title>
<style>
table {
width: 50vw;
color: black;
border: 3px solid black;
}
table td {
padding: 5px;
border: 3px solid black;
max-width: 50%;
}
#header td {
background-color: gray;
border-radius: 5px;
}
</style>
</head>
<body>
<?php
include('../../../dbconnection.php');
$sql = "SELECT * FROM car
JOIN garage ON car.garage = garage.garageid
JOIN owner ON car.owner = owner.ownerid
ORDER BY garagename";
$stmt = $dbconn->prepare($sql);
// fetch width column names, create a table
$data = array();
$stmt->execute($data);
$output = "<table>";
$output .= "<tr id='header'>" .
"<td>Bil ID</td>" .
"<td>Registreringsnummer</td>" .
"<td>Färg</td>" .
"<td>Garage</td>" .
"<td>Ägare</td>".
"</tr>";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$carid = htmlentities($res['carid']);
$regnr = htmlentities($res['regnr']);
$color = htmlentities($res['color']);
$garage = htmlentities($res['garagename']);
$owner = htmlentities($res['ownername']);
$output .= "<tr>" .
"<td>$carid</td>" .
"<td>$regnr</td>" .
"<td>$color</td>" .
"<td>$garage</td>" .
"<td>$owner</td>";
}
$output .= "</table>";
echo "$output";
?>
<br><br>
<?php
$sql = "SELECT * FROM garage";
$stmt = $dbconn->prepare($sql);
// fetch width column names, create a table
$data = array();
$stmt->execute($data);
$output = "<table>";
$output .= "<tr id='header'>" .
"<td>Garage ID</td>" .
"<td>Namn</td>".
"</tr>";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$garageid = htmlentities($res['garageid']);
$garagename = htmlentities($res['garagename']);
$output .= "<tr>" .
"<td>$garageid</td>" .
"<td>$garagename</td>";
}
$output .= "</table>";
echo "$output";
?>
<br><br>
<?php
$sql = "SELECT * FROM owner ORDER BY ownername";
$stmt = $dbconn->prepare($sql);
// fetch width column names, create a table
$data = array();
$stmt->execute($data);
$output = "<table>";
$output .= "<tr id='header'>" .
"<td>Ägare ID</td>" .
"<td>Namn</td>".
"</tr>";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$ownerid = htmlentities($res['ownerid']);
$ownername = htmlentities($res['ownername']);
$output .= "<tr>" .
"<td>$ownerid</td>" .
"<td>$ownername</td>";
}
$output .= "</table>";
echo "$output";
?>
<?php $dbconn = null; ?>
</html>