Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbserverprogrammering/exercises/mysqlintro/garage/

dbconnection.php
insert.php
select.php
select3d.php
selectOwnerOrder.php
selectSortByG.php

select.php

105 lines UTF-8 Windows (CRLF)
<?php 
session_start
();
?>
<!-- selectposts.php -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Select</title>
<style type="text/css">
    body{
        font-family: arial;
    }
    table{
        width: 200px;
        margin: auto;
        border: 1px black solid;
    }
</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 "<table><caption>Tillgängliga garage:</caption><th>GarageID</th><th>Namn</th>";
    while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
        
$output .= "<tr>".
            
"<td>".htmlentities($res['garageid'])."</td>".
            
"<td>".htmlentities($res['name'])."</td>".
        
"</tr>";
    }
    
$output .= "</table>";
    echo 
"$output";
}
catch(
PDOException $e)
{
    echo 
$sql "<br />" $e->getMessage();
}
try {

     
//The SQL SELECT statement 
    
$sql "SELECT * FROM owner";
    
$stmt $dbconn->prepare($sql);

    
$data = array();  
    
$stmt->execute($data);
    
$output "<table><caption>Användare:</caption><th>OwnerID</th><th>Namn</th>";
    while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
        
$output .= "<tr>".
            
"<td>".htmlentities($res['ownerid'])."</td>".
            
"<td>".htmlentities($res['name'])."</td>".
        
"</tr>";
    }
    
$output .= "</table>";
    echo 
"$output";
}
catch(
PDOException $e)
{
    echo 
$sql "<br />" $e->getMessage();
}
try {

     
//The SQL SELECT statement 
    
$sql "SELECT * FROM car";
    
$stmt $dbconn->prepare($sql);

    
$data = array();  
    
$stmt->execute($data);
    
$output "<table><caption>Registrerade bilar:</caption>
    <th>Bil ID</th>
    <th>RegNr</th>
    <th>Färg</th>
    <th>GarageID</th>
    <th>OwnerID</th>"
;
    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['garage'])."</td>".
            
"<td>".htmlentities($res['owner'])."</td>".
        
"</tr>";
    }
    
$output .= "</table>";
    echo 
"$output";
}
catch(
PDOException $e)
{
    echo 
$sql "<br />" $e->getMessage();
}

$dbconn null;

?>
<button onclick="window.location.href='../garage'">Meny</button>
</body>
</html>