1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| <html>
<head>
<script language="JavaScript">
function Inc(champ) // Augmentation du nombre d'unités
{
champ.value++;
}
function Dec(champ) // Diminution du nombre d'unités (avec test si < à 0)
{
champ.value--;
if(champ.value<0)
{
champ.value=0;
alert("Pas moins que 0");
}
}
</script>
</head>
<body>
<form action="" method="POST">
<table>
<?php
mysql_connect("localhost","root",""); // Connexion BDD
mysql_select_db("toutou");
$query = "SELECT * FROM objets";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$nom = $row['nom']; // Nom de l'objet
$prix_unit = $row['prix']; // PU de l'objet
echo "<tr><td>$nom</td><td><input type='text' name='$nom' value='0' /> (x$prix_unit)</td>
<td><input type='button' onclick='Inc($row[nom])' value='^' /></td>
<td><input type='button' onclick='Dec($row[nom])' value='v' /></td></tr>
<input type='hidden' name='prix_$nom' value='$prix_unit' />";
}
echo "
</table>
<input type='submit' name='acheter' value='Acheter' />
</form>
</body>
</html>
"; |
Partager