Buonanotte o grandi forumisti!
Mi domandavo, visto che sto scrivendo questo scriptino, vorrei aggiungerci una feature interessante, solo che non so proprio da che parte cominciare. Vorrei in pratica fare in modo che l'amico per cui sto facendo questo piccolo regalo, possa tramite il codice a barre, inserire i prodotti che un determinato cliente compra, farlo comparire nella tabella e successivamente fare il calcolo complessivo della spesa totale... fin'ora ho scritto questo, ma ovviamente è sbagliato in più punti, così come il ragionamento applicato al problema. Cosa dovrei fare secondo voi?
Codice PHP:
<html>
[url="index.html"]Torna alla pagina principale[/url]</h1>
<body style="background-color:red">
<form action="" method="post">
<h1> Calcolo lista della spesa </h1>
<table border="1">
<tr>
<th>Codice a barre: <input type="text" name="codice" /></th>
</tr>
</table>
</br>
<input type="submit" value="Recupera prodotto"/>
</form>
</body>
</html>
<?
require "connect.php";
if (isset($_POST['codice']))
{
$codice = $_POST['codice'];
$sql = "SELECT codice,nome,prezzo FROM prodotti WHERE $codice";
$res = mysql_query($sql, $link);
echo '
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<th>[b]<h3>Codice a barre</h3>[/b]</th>
<th>[b]<h3>Nome</h3>[/b]</th>
<th>[b]<h3>Prezzo</h3>[/b]</th>
</tr>';
$prezzo = 0;
$row = mysql_fetch_array($res);
while ($row = mysql_fetch_array($res)){
echo '
<tr>
<th>' . $row['codice'] . '</th>
<th>' . $row['nome'] . '</th>
<th>' . $row['prezzo'] . '</th>
</tr> ';
$prezzo += $row['prezzo'];
}
echo "</table>";
echo "Prezzo totale: $prezzo </table>";
}
?>
Grazie a tutti. Siete sempre dei grandi!