Bonjour, j'ai pour projet de gérer les stock de médicament d'une entreprise. Je suis en cour de développement d'une partie ou je veux récupérer via une combo-box un nom de médicament, rentrer le nombre de médicament que l'on veut acheter. Puis via un input grisé, calculer et afficher automatiquement le montant total en prenant compte de la quantité et du prix via le médicament choisi. J'essaye de trouver une solution via ajax pour avoir quelque chose de rapide et fluide sans rechargement de la page et j'avoue que je galère un peu vu qu'on vient de commencer ajax. voici le code de ma page principale:
Code html : 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 <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <link href="includes/tab.css" rel="stylesheet" type="text/css" media="all" /> <?php $omedicament = new CMedicaments(); $tabMedic = $omedicament->getTabMedicament(); $onommedic = new CMedicaments(); $tabNomMedic = $onommedic->getTabNomMedicament(); ?> <center><div style="height:300px; width: 850px ;overflow: auto;"> <table class="table"> <thead class="thead-light"> <tr> <th scope="col">NOM</th> <th scope="col">QUANTITÉ</th> <th scope="col">PRIX</th> </tr> </thead> <tbody> <?php foreach ($tabMedic as $omedicament) { ?> <tr> <td><?=$omedicament->nom ?></td> <td><center><?=$omedicament->nombre?></center></td> <td><center><?=$omedicament->prix ?></center></td> <?php } ?> </tbody> </table> </div> <br> <center> <form class="form-inline" method="POST" action="gestion.php"> <div class="form-group "> <span class="glyphicon glyphicon-search"></span> <label for="nomMedicament">Choisir le Médicament</label> <br> <select name="nomMedicament" style="overflow:auto;"> <?php foreach ($tabNomMedic as $nomMedicament) { echo "<option value='".$nomMedicament."'>".$nomMedicament."</option>"; } ?> </select> <br><br> <div class="form-group"> <label class="control-label">Selectionner la quantité:</label> <input type="text" class="form-control" name="<?php $nombre?>" required placeholder="Entrez un nombre"> </div> <br><br> <?php $cmedo = new CMedicaments(); $prix = $cmedo->calculPrix($nomMedicament) ?> <div class="form-group"> <label class="control-label">Prix total:</label> <input type="text" class="form-control" name="prix" disabled="disable" value="<?php echo $prix; ?>" required placeholder=""> </div> <br><br> <button type="submit" class="btn btn-default">Ajouter</button> </div> </form> </center> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("input:text").name("prix").val('$prix'); }); }); </script> </body> </html>
et enfin voici le code de ma classe cmédicament
merci d'avance pour les courageux qui seront capable de m'apporter de l'aide
Code php : 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 <?php class CMedicament{ public $id; public $nom; public $nombre; public $prix; public $taille; public $detail; function __construct($sid,$snom,$snombre,$sprix,$staille,$sdetail) //s pour send param envoyé { $this->id = $sid; $this->nom = $snom; $this->nombre = $snombre; $this->prix = $sprix; $this->taille = $staille; $this->detail = $sdetail; } } class CMedicaments { private $tabMedicament; private $tabNomMedicament; public function __construct() //s pour send param envoyé { try { $query = "SELECT * FROM medicament ORDER BY nomMedicament ASC"; $odao = new Cdao(); $lesMedicaments = $odao->gettabDataFromSql($query); foreach ($lesMedicaments as $unMedicament) { $omedicament = new CMedicament($unMedicament['idMedicament'],$unMedicament['nomMedicament'],$unMedicament['nombreMedicament'],$unMedicament['prixMedicament'],$unMedicament['Taille'],$unMedicament['detail']); $this->tabMedicament[] = $omedicament; } $query1 = "SELECT nomMedicament FROM medicament"; $lesMedic = $odao->gettabDataFromSql($query1); foreach ($lesMedic as $nomMedic) { $this->tabNomMedicament[] = $nomMedic['nomMedicament']; } } catch(PDOException $e) { $msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage(); die($msg); } } function getTabMedicament() { return $this->tabMedicament; } function getTabNomMedicament() { return $this->tabNomMedicament; } function calculPrix($nommedic) { $query = "SELECT prixMedicament FROM medicament WHERE nomMedicament= '$nommedic'"; $odao = new Cdao(); $req = $odao->getData($query); return $req; } }
Cordialement Zarkvulcor
Partager