Webbserverprogrammering 1

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)
<!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>