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 14/03/2010, 17h16   #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 Récapitulatif est mal interprété

Bonjour,

J'essaye de mettre en place un récapitulatif des montants de ma base de donnée par année et par région, mais voila le code de mon script est mal interprété
Ci-joint la structure de mes deux table concerné

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
 
 
--
-- Structure de la table `facture`
--
 
CREATE TABLE IF NOT EXISTS `facture` (
  `fact_id` varchar(7) NOT NULL,
  `fact_facture` varchar(14) NOT NULL,
  `fact_intitule` varchar(60) NOT NULL,
  `fact_montant` double NOT NULL,
  `fact_session` tinytext NOT NULL,
  `fact_date` varchar(20) NOT NULL,
  `fact_echeance` varchar(20) NOT NULL,
  `fact_type` varchar(15) NOT NULL,
  `fact_annee` varchar(5) NOT NULL,
  PRIMARY KEY (`fact_facture`),
  UNIQUE KEY `facture` (`fact_facture`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-- --------------------------------------------------------
 
--
-- Structure de la table `societe`
--
 
CREATE TABLE IF NOT EXISTS `societe` (
  `soc_id` varchar(7) NOT NULL,
  `soc_societe` tinytext NOT NULL,
  `soc_adherent` tinytext NOT NULL,
  `soc_adressea` tinytext NOT NULL,
  `soc_adresseb` tinytext NOT NULL,
  `soc_postal` varchar(30) NOT NULL,
  `soc_ville` tinytext NOT NULL,
  `soc_region` tinytext NOT NULL,
  `soc_enseigne` tinytext NOT NULL,
  `soc_telephone` tinytext NOT NULL,
  `soc_fax` tinytext NOT NULL,
  `soc_siret` tinytext NOT NULL,
  `soc_code` varchar(1) NOT NULL,
  PRIMARY KEY (`soc_id`),
  UNIQUE KEY `id_numero` (`soc_id`),
  UNIQUE KEY `id_numero_2` (`soc_id`),
  KEY `id_numero_3` (`soc_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
et le code de ma page

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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
 
<?php
session_start ();
echo "Utilisateur : ";
echo $_SESSION['pseudo'];
if (($_SESSION['level']==1) AND ($_SESSION['level']==2))
header('location:../index.php');
echo'<br>';
?>
 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" media="screen" type="text/css" title="Design" href="#" />
</head>
 
<body font-size='xx-small'>
 
<h2><center><b><u> Récapitulatif </u></b></center></h2><br>
 
<?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>region</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
 
$rqt = mysql_query("SELECT fact_id, soc_ville, soc_telephone, soc_fax, soc_siret, soc_enseigne,soc_code, soc_region, soc_societe, SUM(fact_montant) AS fact_montant, soc_adherent, fact_annee FROM societe, facture WHERE fact_id = soc_id GROUP BY soc_code") or die(mysql_error());
 
 
if(mysql_num_rows($rqt) > 0)
	{
	while($tableau = mysql_fetch_array($rqt))
		{
		$id = $tableau['fact_id'];
		$code = $tableau['soc_code'];
		$societe = $tableau['soc_societe'];
		$adherent = $tableau['soc_adherent'];
		$ville = $tableau['soc_ville'];
		$region = $tableau['soc_region'];
		$enseigne = $tableau['soc_enseigne'];
		$telephone = $tableau['soc_telephone'];
		$fax = $tableau['soc_fax'];
		$siret = $tableau['soc_siret'];
 
		$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
 
		$mont = 0;
 
//********************************************************************************//		
//                              calcul par année                                 //
//******************************************************************************//
 
			if($tableau['fact_annee'] == '20081')
				{
				$ant08 += $tableau['fact_montant']; //anterieur a 2008
				}
			if($tableau['fact_annee'] == '20080')
				{
				$a08 += $tableau['fact_montant']; // année 2008
				}
			if($tableau['fact_annee'] == '20090')
				{
				$a09 += $tableau['fact_montant']; // année a 2009
				}
			if($tableau['fact_annee'] == '20100')
				{
				$a10 += $tableau['fact_montant']; // année a 2010
								}
			if($tableau['fact_annee'] == '20110')
				{
				$a11 += $tableau['fact_montant'];  // année a 2011
				}
			if($tableau['fact_annee'] == '20101')
				{
				$a_1 += $tableau['fact_montant'];  // Mons d'un mois
				}
			//fin du calcul par année//
			$mont += $tableau['fact_montant'];
 
//***********************************************************************************************************************//		
//                                 Totalisation par colonne selon l'année                                                //
//***********************************************************************************************************************//
			if(($tableau['soc_code'] == $code) AND ($tableau['soc_region'] == $region))
				{
				$Tant08 += $ant08;
				}
			if(($tableau['soc_code'] == $code) AND ($tableau['soc_region'] == $region))
				{
				$Ta08 += $a08;
				}
			if(($tableau['soc_code'] == $code) AND ($tableau['soc_region'] == $region))
				{
				$Ta09 += $a09;
				}	
			if(($tableau['soc_code'] == $code) AND ($tableau['soc_region'] == $region))
				{
				$Ta10 += $a10;
				}	
			if(($tableau['soc_code'] == $code) AND ($tableau['soc_region'] == $region))
				{
				$Ta11 += $a11;
				}	
			if(($tableau['soc_code'] == $code) AND ($tableau['soc_region'] == $region))
				{
				$Ta_1 += $a_1;
				}
			// fin du calcul des totaux par colonne
 
 
//**************************************************************************************			
// création du total par ligne " vérification avec le fact_montant "
 
$Tmont_2 = ($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><font size ='2.5'>".$region."<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='1' 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>");
 
?>

Je vous remerci de l'aide que vous pourriez m'apporter.

Ci-joint en pièce joint le résultat obtenu à ce jour

Runcafre91

Dernière modification par runcafre91 ; 05/04/2010 à 23h29.
runcafre91 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/03/2010, 17h20   #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
Si tu pouvais nous expliciter ce qui ne va pas.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/03/2010, 17h48   #3
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
Citation:
Envoyé par sabotage Voir le message
Si tu pouvais nous expliciter ce qui ne va pas.
Bonjour,

merci de votre réponse, c'es la premier partie du calcul qui me joue des tours,
Je dois faire un total par ligne par année.

Mais voila a le code ne traite pas en totalité les éléments.
Si e prend le cas de la première ligne region nord en principe je dois avoir un montant dans la plupart des colonnes or ici ce n'est pas le cas.

ci-dessous la partie du code concernée

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
 
 
 
//********************************************************************************//		
//                              calcul par année                                 //
//******************************************************************************//
 
if($tableau['fact_annee'] == '20081')
	{
	$ant08 += $tableau['fact_montant']; //anterieur a 2008
	}
if($tableau['fact_annee'] == '20080')
	{
	$a08 += $tableau['fact_montant']; // année 2008
	}
if($tableau['fact_annee'] == '20090')
	{
	$a09 += $tableau['fact_montant']; // année a 2009
	}
if($tableau['fact_annee'] == '20100')
	{
	$a10 += $tableau['fact_montant']; // année a 2010
             }
if($tableau['fact_annee'] == '20110')
	{
             $a11 += $tableau['fact_montant'];  // année a 2011
	}
if($tableau['fact_annee'] == '20101')
	{
	$a_1 += $tableau['fact_montant'];  // Mons d'un mois
	}
//fin du calcul par année//
Au niveau des totaux par colonne cela ne pose pas de problème

Merci de votre aide

Runcafre91
runcafre91 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/03/2010, 18h45   #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
Contrôle ce que retourne ta requête, tu devrais voir tout de suite ce qui ne va pas.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/03/2010, 20h31   #5
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
Citation:
Envoyé par sabotage Voir le message
Contrôle ce que retourne ta requête, tu devrais voir tout de suite ce qui ne va pas.
Re,
Merci de votre réponse, j'ai fait une vérification de la requête dans phpadmin, c'est ma requete qui foire le tout.

En fait il fait un regroupement que sur deux année au lieu de tout prendre.

Ci-joint le résultat que j'obtiens dans phpadmin

Pour info j'ai retiré les champs qui ne me sert a ien de ma requête

Voir pièce jointe

Runcafre91

Dernière modification par runcafre91 ; 05/04/2010 à 23h29.
runcafre91 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/03/2010, 20h34   #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
C'est normal, tu as un GROUP sur soc_region donc une seule ligne par soc_region.
A voir selon ce que tu veux faire, si tu peux grouper aussi sur le champs de l'année.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/03/2010, 21h54   #7
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
Citation:
Envoyé par sabotage Voir le message
C'est normal, tu as un GROUP sur soc_region donc une seule ligne par soc_region.
A voir selon ce que tu veux faire, si tu peux grouper aussi sur le champs de l'année.
Bonsoir,
c'est justement ce que je veux un regroupement par soc_region et le total par année (fact_annee) voir capture écran précédente

Merci de votre aide

Runcafre91
runcafre91 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/03/2010, 22h05   #8
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
Je t'ai dis ce qu'il fallait faire.
sabotage 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 13h23.


 
 
 
 
Partenaires

Hébergement Web