forked from Athox/Projet-PHP-Vente-Bio
/
produit.php
61 lines (54 loc) · 1.42 KB
/
produit.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
include("connection.php");
function afficher_produit($is_fruit){
if($is_fruit){
$requete="SELECT * FROM Produits WHERE `fruit`=true";
}
else{
$requete="SELECT * FROM Produits WHERE `fruit`=false";
}
$idcom=connex("p1306716","Myparam");
$result=@mysql_query($requete,$idcom);
if(!$result){
echo "Lecture impossible";
}
else{
echo "<table cellspacing='0' cellpadding='5'>";
echo "<tr>";
echo "<th>Produit</th><th>Description</th><th>Stock</th><th>Prix</th><th>Quantité</th><th></th>";
echo "</tr>";
while($ligne=mysql_fetch_array($result,MYSQL_NUM)){
echo "<tr id='".$ligne[0]."'>";
echo "<td>".$ligne[1]."</td>";
echo "<td>".$ligne[2]."</td>";
echo "<td>".$ligne[3]."</td>";
echo "<td>".$ligne[4]."</td>";
echo "<td><select name='qte_v[]'>";
for($i=1;$i<=$ligne[3];$i++){
echo"<option>".$i."</option>";
}
echo "</select></td>";
echo '<td><button onclick="addProduit($(this));" class=bouton_produit>Ajouter au panier</button></td>';
echo "</tr>";
}
echo "</table>";
}
}
?>
<div class='box'>
<script>
function addProduit(produit){
window.location.replace("panier.php?product_id="+produit.parent().parent().attr('id')+"&qte_voulu="+produit.parent().parent().find('select').val());
}
</script>
<h2>Fruits Bio</h2>
<?php
afficher_produit(true);
?>
</div>
<div class='box'>
<h2>Légumes bio</h2>
<?php
afficher_produit(false);
?>
</div>