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_3/exercise_3_a/
7 filer
back_button.php
dbconnection.php
index.php
insert_values.php
print_table.php
reset.php
reset_garages_owners.php
dbconnection.php
index.php
insert_values.php
print_table.php
reset.php
reset_garages_owners.php
print_table.php
129 lines ASCII Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
<!DOCTYPE html>
<html lang="sv">
<head>
<title>Show cars</title>
<meta charset="utf-8">
<style type="text/css">
table.outputData {
border-collapse: collapse;
margin: 2em 0;
}
.outputData caption {
margin-bottom: 1em;
}
.outputData th {
font-weight: bold;
}
.outputData td, .outputData th {
padding: 8px;
border: 1px solid #686868;
}
</style>
</head>
<body>
<?php
include('back_button.php');
include ('dbconnection.php');
try {
$sql = "SELECT * FROM garages";
$stmt = $dbconn->prepare($sql);
$stmt->execute();
$output = "
<table class='outputData'>
<caption>
<strong>Garages</strong>
</caption>
<tr>
<th>Index</th>
<th>Name</th>
</tr>
";
while ($response = $stmt->fetch(PDO::FETCH_ASSOC)) {
$output .= "<tr>
<td>".htmlentities($response['garageId'])."</td>
<td>".htmlentities($response['name'])."</td>
</tr>";
}
$output .= "</table>";
echo $output;
}
catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
//
}
try {
$sql = "SELECT * FROM owners";
$stmt = $dbconn->prepare($sql);
$stmt->execute();
$output = "
<table class='outputData'>
<caption>
<strong>Owners</strong>
</caption>
<tr>
<th>Index</th>
<th>Name</th>
</tr>
";
while ($response = $stmt->fetch(PDO::FETCH_ASSOC)) {
$output .= "<tr>
<td>".htmlentities($response['ownerId'])."</td>
<td>".htmlentities($response['name'])."</td>
</tr>";
}
$output .= "</table>";
echo $output;
}
catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
//
}
try {
$sql = "SELECT * FROM cars";
$stmt = $dbconn->prepare($sql);
$stmt->execute();
$output = "
<table class='outputData'>
<caption>
<strong>Cars</strong>
</caption>
<tr>
<th>Index</th>
<th>Registration</th>
<th>Color</th>
<th>Garage</th>
<th>Owner</th>
</tr>
";
while ($response = $stmt->fetch(PDO::FETCH_ASSOC)) {
$output .= "<tr>
<td>".htmlentities($response['carId'])."</td>
<td>".htmlentities($response['registrationNmbr'])."</td>
<td>".htmlentities($response['color'])."</td>
<td>".htmlentities($response['garage'])."</td>
<td>".htmlentities($response['owner'])."</td>
</tr>";
}
$output .= "</table>";
echo $output;
}
catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
//
}
$dbconn = null;
?>
</body>
</html>