Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/ovning9/3/
laggatill.php
skapatabell.php
visa.php
visaB.php
visaC.php
visaD.php
visaE.php
visaD.php
108 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Select</title>
<style>
table{
border: 1px black solid;
}
td{
width: 100px;
}
tr{
width: 100px;
}
th{
width: 100px;
text-align: center;
background-color: grey;
}
</style>
</head>
<body>
<?php
include ('../dbconnection.php');
try {
/*** The SQL SELECT statement ***/
$sql = "SELECT * FROM garage";
$stmt = $dbconn->prepare($sql);
$data = array();
$stmt->execute($data);
$output = "<h1>GARAGE!</h1><table>
<tr>
<th> Index </th>
<th> Namn </th>
</tr>
";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$output .= "<tr>".
"<td>".htmlentities($res['garageid'])."</td>".
"<td>".htmlentities($res['name'])."</td>".
"</tr>";
}
$output .= "</table>";
echo "$output";
$sql = "SELECT * FROM owner
ORDER BY name";
$stmt = $dbconn->prepare($sql);
$data = array();
$stmt->execute($data);
$output = "<h1>OWNER!</h1><table>
<tr>
<th> Index </th>
<th> Namn </th>
</tr>
";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$output .= "<tr>".
"<td>".htmlentities($res['ownerid'])."</td>".
"<td>".htmlentities($res['name'])."</td>".
"</tr>";
}
$output .= "</table>";
echo "$output";
$sql = "SELECT car.carid, car.regnr, car.color, garage.name AS garagename, owner.name AS ownername
FROM car
INNER JOIN garage ON car.garage = garage.garageid
INNER JOIN owner ON car.owner = owner.ownerid
ORDER BY garagename
";
$stmt = $dbconn->prepare($sql);
$data = array();
$stmt->execute($data);
$output = "<h1>CAR!</h1><table>
<tr>
<th> Index </th>
<th> Reg. Nummer </th>
<th> Färg </th>
<th> Garage-id </th>
<th> Owner-id </th>
</tr>
";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$output .= "<tr>".
"<td>".htmlentities($res['carid'])."</td>".
"<td>".htmlentities($res['regnr'])."</td>".
"<td>".htmlentities($res['color'])."</td>".
"<td>".htmlentities($res['garagename'])."</td>".
"<td>".htmlentities($res['ownername'])."</td>".
"</tr>";
}
$output .= "</table>";
echo "$output";
}
catch(PDOException $e)
{
echo $sql . "<br />" . $e->getMessage();
}
$dbconn = null;
?>
<a href="../ovn_sql3.php">Tillbaks till meny</a>
</body>
</html>