Files
northwind-ordini-php/index.php
2026-02-25 11:09:14 +01:00

72 lines
2.4 KiB
PHP

<?php
require_once "db_conf.php";
$customer_id = $_GET["customerId"];
$order_id = $_GET["orderId"];
$sql = "";
if (isset($_GET["customerId"])) {
$sql = "SELECT o.* FROM Orders o INNER JOIN Customers c ON o.CustomerID = c.CustomerID WHERE c.CustomerID = " . $customer_id . ";";
}
else if (isset($_GET["orderId"])) {
$sql = "SELECT p.*, od.quantity AS order_quantity FROM Orders o INNER JOIN OrderDetails od ON o.OrderID = od.OrderID INNER JOIN Products p ON od.ProductID = p.ProductID WHERE o.OrderID =" . $order_id . ";";
}
else {
$sql = "SELECT DISTINCT CustomerID, CustomerName FROM Customers;";
}
$result = mysqli_query($conn, $sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Northwind Clients</title>
<link rel="stylesheet" href="style.css">
<style>
a{
color: white;
}
</style>
</head>
<body>
<?php
if($result){
if(isset($_GET["customerId"])){
# Tabella Prodotti
echo "<h2>Ordini del cliente " . $customer_id . "</h2>";
echo "<table>";
echo "<tr>";
if (mysqli_num_rows($result) == 0) {
echo "<th>Il cliente ". $customer_id ." non ha ordini</th>";
}
else {
echo "<th>ID Ordine</th>";
}
echo "</tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td><a href='index.php?orderId=" . $row['OrderID'] ."'>" . $row['OrderID'] ."</a></td>" ;
echo "</tr>";
}
echo "</table>";
}
else if(isset($_GET["orderId"])){
echo "WIP";
}
else {
echo "<form method='GET' action='index.php'>";
echo "<select id='customerId' name='customerId'>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['CustomerID'] . "'>" . $row['CustomerID'] . " - " . $row['CustomerName'] . "</option>";
}
echo "</select>";
echo "<input type='submit' value='Visualizza Ordini'>";
echo "</form>";
}
}
?>
</body>
</html>