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 07/03/2010, 09h45   #1
Membre du Club
 
Homme Stéphane A.
Inscription : décembre 2008
Messages : 286
Détails du profil
Informations personnelles :
Nom : Homme Stéphane A.
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Secteur : Distribution

Informations forums :
Inscription : décembre 2008
Messages : 286
Points : 67
Points : 67
Par défaut Problème de calcul

Bonjour,

Afin d'optimiser le traitement d'un script, j'ai renommer les champs de mes tables. J'avais un récapitulatif qui est état composé de plusieurs requetes qui me donnais une ventillation des montant par ligne par année et par secteur

Voila j'ai refait le script en intégrant qu'une seul requête, voila une parti du code s'execute normalement mais au niveau de la répartition il y a un soucis

ci-dessous le fichier de traitement
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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
 
<?php
 
include('../inc/inc_connexion.php');
include('../inc/fonction.php');
 
$ligne = "<table BORDER=1 BORDERCOLOR=#CCCCCC BGCOLOR=#fffccc CELLSPACING=0 CELLPADDING=1 WIDTH=98% ALIGN=center font-family='Verdana' font-size='xx-small' >
			<td bgcolor='#669999'><b><u>Code</u></b></td>
			<td bgcolor='#669999'><b><u>region</u></b></td>
			<td bgcolor='#669999'><b><u>Site</u></b></td>
			<td bgcolor='#669999'><b><u>Contacte</u></b></td>
			<td bgcolor='#669999' WIDTH=15px><b><u>Montant</u></b></td>
			<td bgcolor='#669999' WIDTH=15px><b><u>Anterieur à 2008</u></b></td>
			<td bgcolor='#669999' WIDTH=15px><b><u>2008</u></b></td>
			<td bgcolor='#669999' WIDTH=15px><b><u>2009</u></b></td>
			<td bgcolor='#669999' WIDTH=15px><b><u>2010</u></b></td>
			<td bgcolor='#669999' WIDTH=15px><b><u>2011</u></b></td>
			<td bgcolor='#669999' WIDTH=15px><b><u>-1 mois</u></b></td>
			<td bgcolor='#669999' WIDTH=15px><b><u>Vérif</u></b></td>";
 
$total = 0;	
//ici initialisation des variables total pour chaque année//
		$Tant08 = 0;
		$Ta08 = 0;
		$Ta09 = 0;
		$Ta10 = 0;
		$Ta11 = 0;
		$Ta_1 = 0; //c'est pour les facture datant d'un - d'un mois ($Ta_1)//
		$Tmont_3 = 0; // sert à la totalisation de la colonne des totaux
 
 
 
	$rqt2 = mysql_query("SELECT DISTINCT fact_annee, localisation, pseudo, code, SUM(fact_montant) AS fact_montant, soc_code, nom_region FROM region, societe, facture WHERE nom_region = soc_region AND soc_id = fact_id AND soc_code = code GROUP BY soc_region ORDER BY code
")or die(mysql_error());
 
 
 
	while($tableau = mysql_fetch_array($rqt2))
		{
		$code = $tableau['code'];
		$localisation = $tableau['localisation'];
		$pseudo = $tableau['pseudo'];		
		$region = $tableau['nom_region'];
 
 
		$ant08 = 0; //ici l'initialisation des variables par année//
		$a08 = 0;
		$a09 = 0;
		$a10 = 0;
		$a11 = 0;
		$a_1 = 0;
		$Tmont_2 = 0; // sert a la totalisation des lignes
	$fact_annee= "";
 
	$mont = 0;
 
			//calcul par année//
			if(($tableau['fact_annee'] == '20081') AND ($tableau['nom_region'] == $region))
				{
				$ant08 += $tableau['fact_montant']; // Anterieur a 2008
				}
			if(($tableau['fact_annee'] == '20080') AND ($tableau['nom_region'] == $region))
				{
				$a08 += $tableau['fact_montant']; // Année 2008
				}
			if(($tableau['fact_annee'] == '20090') AND ($tableau['nom_region'] == $region))
				{
				$a09 += $tableau['fact_montant']; // Année 2009
				}
			if(($tableau['fact_annee'] == '20100') AND ($tableau['nom_region'] == $region))
				{
				$a10 += $tableau['fact_montant']; // Année 2010
								}
			if(($tableau['fact_annee'] == '20110') AND ($tableau['nom_region'] == $region))
				{
				$a11 += $tableau['fact_montant']; // Année 2011
				}
			if(($tableau['fact_annee'] == '20101') AND ($tableau['nom_region'] == $region))
				{
				$a_1 += $tableau['fact_montant']; // Moins d'un mois
				}
			//fin du calcul par année//
			$mont += $tableau['fact_montant'];
 
//***********************************************************************************************************************		
// Calcul des totaux des colonnes en fonction de la region et de l'année
 
			if(($tableau['soc_code'] == $code) AND ($tableau['nom_region'] == $region))
				{
				$Tant08 += $ant08;
				}
			if(($tableau['soc_code'] == $code) AND ($tableau['nom_region'] == $region))
				{
				$Ta08 += $a08;
				}
			if(($tableau['soc_code'] == $code) AND ($tableau['nom_region'] == $region))
				{
				$Ta09 += $a09;
				}	
			if(($tableau['soc_code'] == $code) AND ($tableau['nom_region'] == $region))
				{
				$Ta10 += $a10;
				}	
			if(($tableau['soc_code'] == $code) AND ($tableau['nom_region'] == $region))
				{
				$Ta11 += $a11;
				}	
			if(($tableau['soc_code'] == $code) AND ($tableau['nom_region'] == $region))
				{
				$Ta_1 += $a_1;
				}
			// fin du calcul des totaux par colonne
 
//**************************************************************************************			
// création du total par ligne " vérification avec le montant "
 
			$Tmont_2 = ($ant08 + $a08 + $a09 + $a10 + $a11 + $a_1); 
 
			$mont = ($ant08 + $a08 + $a09 + $a10 + $a11 + $a_1);
 
			$Tmont_3 += $Tmont_2;
 
 
//*****************************************************************************************
// Calcul du total final par région
		$total += $mont; 	
//**********************************************************************************************************************
 
		if($mont > 0)
			{
			$ligne .= "<tr>
						<td align='center'><font size ='2.5'><a href='detail_region.php?code='$code' target='_self'>".$code."</a><font></td>
						<td><font size ='2.5'>".$region."<font></td>
						<td align='left'><font size ='2.5'>".$localisation."<font></td>
						<td align='left'><font size ='2.5'>".$pseudo."<font></td>
						<td align='right' bgcolor='#669999'><font size ='2.5'>".$mont."<font></td>
						<td align='right'><font size ='2.5'>".$ant08."<font></td>
						<td align='right'><font size ='2.5'>".$a08."<font></td>
						<td align='right'><font size ='2.5'>".$a09."<font></td>
						<td align='right'><font size ='2.5'>".$a10."<font></td>
						<td align='right'><font size ='2.5'>".$a11."<font></td>
						<td align='right'><font size ='2.5'>".$a_1."<font></td>
						<td align='right' bgcolor='#669999'><font size ='2.5'>".$Tmont_2."<font></td></tr>"; // total de la ligne //
			}
		}	
 
$ligne .= "<tr><td colspan='4' bgcolor='#669999'><font size ='2.5'>Total Final<font></td><td align='right' bgcolor='#669999'><font size ='2.5'>".$total."<font></td>";
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'><font size ='2.5'>".$Tant08."<font></td>";
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'><font size ='2.5'>".$Ta08."<font></td>";
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'><font size ='2.5'>".$Ta09."<font></td>";
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'><font size ='2.5'>".$Ta10."<font></td>";
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'><font size ='2.5'>".$Ta11."<font></td>";
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'><font size ='2.5'>".$Ta_1."<font></td>"; // concerne les factures de moins d'un mois //
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'><font size ='2.5'>".$Tmont_3."<font></td></tr>"; // total des differents totaux //
 
$ligne .= "</table>";	
 
echo ("$ligne </br>");
 
?>

En pièce joint le resultat que j'obtiens si cela peux aider

je vous remercie de votre aide,

************************
Re,

J'ai essayé de tourner le problème dans tous les sens et j'arrive toujours pas a avoir le résultat voulu

Quelqu'un pourrait m'aider sur ce problème

Je vous remercie

Runcafre91

Dernière modification par runcafre91 ; 05/04/2010 à 23h29.
runcafre91 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 +1. Il est actuellement 04h20.


 
 
 
 
Partenaires

Hébergement Web