Files
techstore-ordermg/ordini.php

49 lines
1.2 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], $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>
<table>
<tr>
<th>ID Ordine</th>
<th>Prodotto</th>
<th>Importo</th>
</tr>
<?php
for($i=0; $i<count($ordini); $i++){
echo "<tr><td>" . $ordini[$i]->id . "</td><td>" . $ordini[$i]->product . "</td><td>" . $ordini[$i]->importo . "€</td></tr>";
}
?>
</table>
</body>
</html>