Bonjour à tous,
Y'aurait-il un bonne âme pour m'aider. Voilà je débute en PHP, je dois créer un panier.
J'ai réussi à faire de l'incrémentation et de la décrémentation pour mes produits. Par contre là où je sèche, c'est comment je peux récupérer les tarifs de mes produits stockés dans une base MySQL et effectuer les calculs (montant ht, ttc par article puis montant total).
Voici mon code :
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 <?php session_start(); if (isset($_GET["prod"])) { switch ($_GET["sens"]) { case "ajout" : $_SESSION[$_GET["prod"]] ++; break; case "sup" : $_SESSION[$_GET["prod"]] --; //-- si la quantité < 1, le produit est supprimé du panier ----- if ($_SESSION[$_GET["prod"]] < 1) unset($_SESSION[$_GET["prod"]]); break; } } ?> <?php include_once 'class.php'; //Lecture de la Base // requete sur la table Licences open(); $Produit='"'.$_GET['prod'].'"'; $requete2="SELECT Tarifs from Licences where ProduitFMP=$ProduitFMP"; $result2=mysql_query($requete2); if($result2==0) { echo "Impossible d'effectuer la requête<br>$requete2"; exit; } $Tarifs=mysql_fetch_row($result2); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1"> </head> <body> <table cellspacing="1" width="65%" align="center"> <tr align="left"> <th>Produit</th> <th>Type de licence</th> <th></th> </tr> <tr> <td>Prod 1</td> <td>Produit Complet</td> <td> <a href="test.php?prod=Prod 1&sens=ajout">Ajouter</a></td> </tr> <tr> <td>Prod 2</td> <td>Mise à jour</td> <td><a href="test.php?prod=Prod 2&sens=ajout">Ajouter</a></td> </tr> <tr> <td>Prod 3</td> <td>Education</td> <td><a href="test.php?prod=Prod 3&sens=ajout">Ajouter</a></td> </tr> </table> </body> </html> </html> <?php echo "<p align=\"center\"><b>contenu de votre panier</b></p>"; foreach($_SESSION as $produit => $quantite) { echo " <table cellspacing=\"1\" width=\"65%\" align=\"center\"> <tr align=\"left\"> <td>$produit</td> <td></td> <td>$quantite</td> <td><a href=\"test.php?prod=$produit&sens=sup\">Enlever</a></td> </tr> </table>"; } echo "<hr><br>"; //--------------------------------------------------------------------------- ?>![]()
Partager