Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 11/03/2011, 11h44   #1
Futur Membre du Club
 
Inscription : avril 2010
Messages : 105
Détails du profil
Informations forums :
Inscription : avril 2010
Messages : 105
Points : 18
Points : 18
Par défaut dispatcher un résultat sql selon le mois..

Bien le bonjour, j'ai un petit soucis, à mon avis c plus un problème de logique..
Je vous explique:

Je veux afficher les la quantité total de produits et ensuite dans un tableau html, dispatcher cette quantité selon les mois.

Exemple:
produit || quantité || janvier || février || mars ect ....
produit x || 6 || 4 || 2 || 0 et que des 0 pour les autres moi

quantité total= 6 dont 4 en janvier et 2 en février

Moi pour le moment ca m'affiche qtté total = 6 mais en janvier = 6 et les autres mois 0 .. Ca me dispatche pas la qtité de produit selon les mois..

Mon code:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
 $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 :
1
2
3
4
5
6
7
8
9
10
11
12
13
 
<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>
date==1 >> janvier ect...

Comment dois je faire pour résoudre mon problème et que la quantité soit réparti correctement selon le mois ???
xavioche77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/03/2011, 12h08   #2
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
reclasses tes données dans un tableau $tab[$produit][$mois]
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/03/2011, 12h11   #3
Futur Membre du Club
 
Inscription : avril 2010
Messages : 105
Détails du profil
Informations forums :
Inscription : avril 2010
Messages : 105
Points : 18
Points : 18
donc si je comprend bien c apres ma requete sql je stocke les résultats dans $tab[$produit][$mois] et après je ré affiche conditionnellement selon le mois ??
xavioche77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/03/2011, 12h14   #4
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
toutafé :
Code :
1
2
3
4
5
6
7
foreach ($tab as $produit=>$quantites) {
for ($mois = 1; $mois < 13; $mois++) {
     echo '<td>';
     echo isset($quantites[$mois]) ? $quantites[$mois] : 0;
     echo '</td>';
}
}
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/03/2011, 12h26   #5
Futur Membre du Club
 
Inscription : avril 2010
Messages : 105
Détails du profil
Informations forums :
Inscription : avril 2010
Messages : 105
Points : 18
Points : 18
euh attend attend

pour mettre le résultat de la requete dans le tableau

$tab[$produit][$mois] = $row->quantite;

ou plutôt $tab[$row->article][$row->date] = $row->quantite;

hum je suis en train de me perdre .......
xavioche77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/03/2011, 12h31   #6
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
le deuxième.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/03/2011, 12h51   #7
Futur Membre du Club
 
Inscription : avril 2010
Messages : 105
Détails du profil
Informations forums :
Inscription : avril 2010
Messages : 105
Points : 18
Points : 18
je suis désolé mais je men sors pas.
j'ai fais ca
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
    while ($row = mysql_fetch_object($query)) {
 
	$tab[$row->article][$row->date] = $row->quantite;
print_r($tab);
	$c^=1;
	$class_fond = "ligne$c"; ?>
    <tr class="ligne <?php echo $class_fond; ?>" onMouseOver="this.className='ligne ligne_survol'" onMouseOut="this.className='ligne <?php echo $class_fond; ?>'">
	<td><?php if ($rech_commandes_site != 9999 && isset($row->id_produit) && $row->id_produit != 999999) { ?><a href="../../catalogue/produits/modif.php?id=<?php echo $row->id_produit ?>" title="Afficher la fiche produit"><?php } echo (isset($row->id_produit) && $row->id_produit == 999999) ? 'Carte de fidélité' : tohtml($row->article); if ($rech_commandes_site != 9999 && isset($row->id_produit) && $row->id_produit != 999999) { ?></a><?php } ?></td>
	<td align="right"><?php if ($row->quantite) echo $row->quantite ?></td>
	<td align="right"><?php if ($rech_commandes_site != 9999 && $row->cadeau) echo $row->cadeau ?></td>
 
 
	<?php
	foreach ($tab as $row->article=>$row->quantite) {
for ($row->date = 1; $row->date < 13; $row->date++) {
     echo '<td>';
    echo isset($row->quantite[$row->date]) ? $row->quantite[$row->date] : 0;
     echo '</td>';
}
}
?>
Je dois m'embrouiller méchamment.

faire ce code là ( comme tu me le donnes dans les post précédent), ca me renvoie un truc bizare:

1er produit : 010000000000
2e produit : 01000000000001000000000
ect ..
c exponentiel
Il devrait y zvoir que 12 chiffres a chaque fois. Là premier produit > 12 chiffres, 2ème > 24 chiffres ect...

Code :
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
 
  <?php
    $total = 0;
    $total_cadeau = 0;
    $tab_cadeau = array();
    $c = 0;
    while ($row = mysql_fetch_object($query)) {
 
	$tab[$row->article][$row->date] = $row->quantite;
print_r($tab);
	$c^=1;
	$class_fond = "ligne$c"; ?>
    <tr class="ligne <?php echo $class_fond; ?>" onMouseOver="this.className='ligne ligne_survol'" onMouseOut="this.className='ligne <?php echo $class_fond; ?>'">
	<td><?php if ($rech_commandes_site != 9999 && isset($row->id_produit) && $row->id_produit != 999999) { ?><a href="../../catalogue/produits/modif.php?id=<?php echo $row->id_produit ?>" title="Afficher la fiche produit"><?php } echo (isset($row->id_produit) && $row->id_produit == 999999) ? 'Carte de fidélité' : tohtml($row->article); if ($rech_commandes_site != 9999 && isset($row->id_produit) && $row->id_produit != 999999) { ?></a><?php } ?></td>
	<td align="right"><?php if ($row->quantite) echo $row->quantite ?></td>
	<td align="right"><?php if ($rech_commandes_site != 9999 && $row->cadeau) echo $row->cadeau ?></td>
 
 
	<?php
foreach ($tab as $produit=>$quantites) {
for ($mois = 1; $mois < 13; $mois++) {
     echo '<td>';
     echo isset($quantites[$mois]) ? $quantites[$mois] : 0;
     echo '</td>';
}
}
Ceci dit quoiqu'il en soit mon problème a la base de séparer les quantités en mois, le problème doit être dans la requête. Même sous phpmyadmin
ca me renvoie pour le produit X la quantité est 6 et le mois 1
alors que pour le produit X la quantité devrait être de 4 pour le mois 1 et de 2 pour le mois 2.
Il me fait toujours la somme et la range dans la premier mois trouvé pour un produit donné.

hum j'ai changer ma requete. Maintenant j'ai un problème niveau php pr réorganiser correctement les choses.

En gros en modifiant la requète j'ai réussi à obtenir:

produit // quantité // janvier // février
produit X // 4 // 4 // 0
produit X // 2 // 0 // 2


Sauf que je veux que produitX ( que les produit qui ont le même nom) soit regroupé.
Donc là je voudrais en sortie:

produit // quantité // janvier // février
produit X // 6 // 4 // 2

Je vais mettre cette nouvelle question dans le forum approprié.
xavioche77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 00h13.


 
 
 
 
Partenaires

Hébergement Web