Files
php-northwind-database/index.php

61 lines
1.7 KiB
PHP

<?php
require_once "db_conf.php";
//Esempio query
$sql = "SELECT CategoryID,CategoryName,Description FROM Categories";
$result = mysqli_query($conn, $sql);
$id = $_GET["Selezione"]
?>
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<form id="formCategorie">
<select name='Selezione' id='category'>
<?php
if ($result){
while($row = mysqli_fetch_assoc($result)){
echo "<option value='" . $row["CategoryID"] . "'>" . $row["CategoryName"] . "</option>";
}
}
?>
</select>
<input type=submit value="Cerca">
</form>
<br>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Unit</th>
<th>Price</th>
</tr>
<?php
if ($result){
$queryProdotti = "SELECT ProductID, ProductName, CategoryID, Unit, Price FROM Products";
$result = mysqli_query($conn, $queryProdotti);
echo "";
while($row = mysqli_fetch_assoc($result)){
if($row["CategoryID"] == $id){
echo "<tr>";
echo "<td>" . $row["ProductID"] . "</td>";
echo "<td>" . $row["ProductName"] . "</td>";
echo "<td>" . $row["Unit"] . "</td>";
echo "<td>" . $row["Price"] . "</td>";
echo "</tr>";
}
}
}
else{
echo "Errore nella query: " . mysqli_error($conn);
}
?>
</table>
</body>
</html>