Bonjour, j'avais un problème avec une requête, et ne trouvant pas solution directement, je pense qu'il est plus simple de faire rapprocher la requête de ce que je veux et de traiter le reste en php pour l'affichage.
Alors ma requète me rend une liste de produit avec pour chaque produit la quantité totale commandé ainsi que cette quantité dispatché selon les dates de la commandes.
J'ai adapter ma requête et j'obtiens des résultats comme ceci :
produit // quantité // janvier // février
produit X // 4 // 4 // 0
produit X // 2 // 0 // 2
produit Y // 5 // 5 // 0
Voilà, maintenant je voudrais regrouper les produits qui ont le même nom ensemble
Donc additionner la quantité totale mais garder les quantités respectives pour janvier et février.
produit // quantité // janvier // février
produit X // 6 // 4 // 2
Le problème que je rencontre c'est que ma variable pour quantité totale et quantité pour un mois est la même $row->quantite.
J'suis perdu, je vois pas quoi faire..
Mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 Code sql $sql = "SELECT date_commande, CONCAT(produits.nom, ' ', produits.poids, ' ', produits.parfum) AS article, SUM(quantite - cadeau) AS quantite, SUM(cadeau) AS cadeau, MONTH( date_commande ) AS date, commandes_detail.id_produit FROM commandes_detail LEFT JOIN commandes ON commandes_detail.id_commande = commandes.id LEFT JOIN produits ON commandes_detail.id_produit = produits.id WHERE statut = 100 GROUP BY id_produit ORDER BY article"; sql_mysql_query($sql);]
et coté php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 Code html <td align="right"><?php if ($row->date==1) echo $row->quantite; ?> </td> <td align="right"><?php if ($row->date==2) echo $row->quantite; ?> </td> <td align="right"><?php if ($row->date==3) echo $row->quantite; ?> </td> <td align="right"><?php if ($row->date==4) echo $row->quantite; ?> </td> <td align="right"><?php if ($row->date==5) echo $row->quantite; ?> </td> <td align="right"><?php if ($row->date==6) echo $row->quantite; ?> </td> <td align="right"><?php if ($row->date==7) echo $row->quantite; ?> </td> <td align="right"><?php if ($row->date==8) echo $row->quantite; ?> </td> <td align="right"><?php if ($row->date==9) echo $row->quantite; ?> </td> <td align="right"><?php if ($row->date==10) echo $row->quantite; ?> </td> <td align="right"><?php if ($row->date==11) echo $row->quantite; ?> </td> <td align="right"><?php if ($row->date==12) echo $row->quantite; ?> </td>
Partager