Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/exercises/databaser/ovn_3/

index.php
lagg_till.php
lista.php
ovn_e.php

ovn_e.php

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

<head>
    <meta charset="utf-8">
    <title>Lista med alla kompisar</title>
    <style>
        table, th, td {
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <?php
    
try {
        
/** @var PDO $dbconn */
        
include("../dbconnection.php");
        
$sql "SELECT * FROM mysqlgrunderovn3car 
        INNER JOIN mysqlgrunderovn3garage ON mysqlgrunderovn3car.garage = mysqlgrunderovn3garage.garageid 
        INNER JOIN mysqlgrunderovn3owner ON mysqlgrunderovn3car.owner = mysqlgrunderovn3owner.ownerid 
        ORDER BY garageName, ownerName"
;
        
$info $dbconn->query($sql);


        echo (
"<table>
  <tr>
    <th>carid</th>
    <th>regnr</th>
    <th>color</th>
    <th>garage</th>
    <th>owner</th>
  </tr>"
);
        while (
$rad $info->fetch(PDO::FETCH_ASSOC)) {
            echo (
"<tr>
    <td>" 
$rad["carid"] . "</td>
    <td>" 
$rad["regnr"] . "</td>
    <td>" 
$rad["color"] . "</td>
    <td>" 
$rad["garageName"] . "</td>
    <td>" 
$rad["ownerName"] . "</td>
    </tr>
    "
);
        }
        echo (
"</table>");



        
$sql "SELECT * FROM mysqlgrunderovn3owner ORDER BY ownerName";
        
$info $dbconn->query($sql);
        echo (
"<table>
  <tr>
    <th>ownerid</th>
    <th>name</th>
  </tr>"
);
        while (
$rad $info->fetch(PDO::FETCH_ASSOC)) {
            echo (
"<tr>
    <td>" 
$rad["ownerid"] . "</td>
    <td>" 
$rad["ownerName"] . "</td>
    </tr>
    "
);
        }
        echo (
"</table>");



        
$sql "SELECT * FROM mysqlgrunderovn3garage";
        
$info $dbconn->query($sql);
        echo (
"<table>
  <tr>
    <th>garageid</th>
    <th>name</th>
  </tr>"
);
        while (
$rad $info->fetch(PDO::FETCH_ASSOC)) {
            echo (
"<tr>
    <td>" 
$rad["garageid"] . "</td>
    <td>" 
$rad["garageName"] . "</td>
    </tr>
    "
);
        }
        echo (
"</table>");
    } catch (
PDOException $e) {
        echo (
$e->getMessage());
    }
    
?>
</body>

</html>