Bonjour,
Dans une application PHP-MySql, je cherche à connaître, par produit, la quantité totale de ses ventes et consommations. Le code suivant ne me donne pas le résultat attendu, et je n'en vois pas la cause.
Y aurait-il une bonne âme pour m'aider?
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 $connect = connection("../commandes.php"); $query = "select cle_prod, denom_prod, (select nom_fourn from fournisseurs_tb where cle_fourn = cde_fournisseur1_prod) from produits_tb where supprime_prod = 0 order by denom_prod"; $resultat = mysql_query($query); while($row = mysql_fetch_array($resultat)) { $tot = 0; $totConso = 0; $totVentes = 0; $requete="select sum(qtte_prod_conso) from conso_tb where cde_prod_conso = $row[0] and (date_conso between '$dDeb' and '$dFin')"; $result = mysql_query($requete, $connect); $num_result_cons = mysql_num_rows($result); if($num_result_cons) { $resultConso = mysql_fetch_array($result); $totConso = $resultConso[0]; } $requete = "select sum(qqte_vente) from ventes_tb where cde_prod_vente = $row[0] and (date_vente between '$dDeb' and '$dFin')"; $res = mysql_query($requete, $connect); $num_result_vente = mysql_num_rows($res); if($num_result_vente) { $resVentes = mysql_fetch_array($res); $totVentes = $resVentes[0]; } $tot = $totConso + $totVentes;
Merci d'avance.
Christophe
Partager