Webbserverprogrammering 1

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