Webbserv1: Källkod
Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/exercises/databas/

admin.php
createtable.php
deletepost.php
deletetable.php
insertdefaultposts.php
insertpost.php
ovn_sqlintro1.php
ovn_sqlintro1_delete.php
ovn_sqlintro1_insert.php
ovn_sqlintro1_skapa.php
ovn_sqlintro1_skrivut.php
ovn_sqlintro1_update.php
ovn_sqlintro2.php
ovn_sqlintro2_delete.php
ovn_sqlintro2_insert.php
ovn_sqlintro2_login.php
ovn_sqlintro2_skapa.php
ovn_sqlintro2_skrivut.php
ovn_sqlintro2_update.php
ovn_sqlintro3.php
ovn_sqlintro3_default.php
ovn_sqlintro3_insert.php
ovn_sqlintro3_skapa.php
ovn_sqlintro3_skrivut.php
selectposts.php
updatepost.php
welcome.php

ovn_sqlintro3_skrivut.php

74 lines ASCII Windows (CRLF)
<!doctype html>
<html>

<body>
<?php
  
include ('../../dbconnection.php');
  try {

    
$sql "SELECT * FROM garage ORDER BY name ASC";
    
$stmt $dbconn->prepare($sql);

    
$data = array();  
    
$stmt->execute($data);
    
$output "<table><caption>Garage</caption>";
    while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
        
$output .= "<tr>".
            
"<td>".htmlentities($res['garageid'])."</td>".
            
"<td>".htmlentities($res['name'])."</td>".
        
"</tr><br>";
    }

    
$output .= "</table>";
    echo 
"$output";

    
$sql "SELECT * FROM owner ORDER BY name ASC";
    
$stmt $dbconn->prepare($sql);

    
$data = array();  
    
$stmt->execute($data);
    
$output "<table><caption>Owners</caption>";
    while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
        
$output .= "<tr>".
            
"<td>".htmlentities($res['ownerid'])."</td>".
            
"<td>".htmlentities($res['name'])."</td>".
        
"</tr><br>";
    }

    
$output .= "</table>";
    echo 
"$output";

    
$sql "SELECT c.carid, c.regnr, c.color, g.name AS garage, o.name AS owner 
      FROM car AS c 
      INNER JOIN garage AS g ON c.garage = g.garageid 
      INNER JOIN owner AS o ON c.owner = o.ownerid 
      ORDER BY g.name ASC, o.name ASC"
;

    
$stmt $dbconn->prepare($sql);
    
$stmt->execute();

    
$output "<table><caption>Cars</caption>";
    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;

?>
</body>
</html>