Files
techstore-ordermg/ordini.php

48 lines
1.3 KiB
PHP

<?php
class User{
public $id;
public $product;
public $importo;
function __construct($id, $productName, $importo){
$this->id = $id;
$this->product = $productName;
$this->importo = $importo;
}
}
$requestedId = $_GET['id'];
$file = fopen("data/ordini.csv", "r") or die("Non riesco a leggere il file, controlla che esista");
$ordini = [];
fgets($file);
while (($linea = fgets($file)) !== false) {
$campi = explode(",", $linea);
if($campi[1] == $requestedId){
array_push($ordini, new User($campi[0], $campi[2], floatval($campi[3])));
}
}
fclose($file);
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>TechStore - Ordini Utente <?php echo $requestedId; ?></title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<a href="index.php">Torna alla lista</a>
<?php
if(count($ordini) == 0){
echo "<p>Nessun ordine associato all'utente</p>";
}
else{
echo "<table><tr><th>ID Ordine</th><th>Prodotto</th><th>Importo</th></tr>";
for($i=0; $i<count($ordini); $i++){
echo "<tr><td>" . $ordini[$i]->id . "</td><td>" . $ordini[$i]->product . "</td><td>" . number_format($ordini[$i]->importo,2,",",".") . "€</td></tr>";
}
echo "</table>";
}
?>
</body>
</html>