Somme des colonnes d'un tableau
Bonjour,
Cela faitun bout de temps que j'ai un problème pour calculer la somme des colonne d'un tableau.
Il s'agit d'un tableau de répartition en fontion des années.
Ci-dessous mon script
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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<?php
if (!empty($titre)) //Si le titre est indiqué, on l'affiche entre les balises <title>
{
echo '<title> '.$titre.' </title>';
}
else //Sinon, on écrit forum par défaut
{
echo '<title> dus region </title>';
}
?>
<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>
<h2><center><b><u> Ventilation des montants par année d'origine</u></b></center></h2><br><br>
<a href="../index.php"> Retour à l'index</a><br>
<?php
include('../includes/inc_conexion.php');
$result = mysql_query("SELECT nom_region FROM region ORDER BY id ASC")or die(mysql_error());
echo '<form action="synthese_region.php" method="post">';
echo '<select name="frm_select_region">';
while ($row = mysql_fetch_array($result))
{
//si c'est le nom de la région qui est commun aux deux tables c'est le champ nom_region que tu dois mettre en value de ton select//
echo '<option value="'.$row['nom_region'].'">'.$row['nom_region'].'</option>';
}
echo '</select>';
echo '<input type="submit" value="Go" />';
echo '</form>';
$var = "";
$ligne = "<table BORDER=1 BORDERCOLOR=#CCCCCC BGCOLOR=#fffccc CELLSPACING=0 CELLPADDING=1 WIDTH=100% ALIGN=left font-family='Verdana' size=2px>
<td bgcolor='#669999'><b><u>Numero</u></b></td>
<td bgcolor='#669999'><b><u>Societe</u></b></td>
<td bgcolor='#669999'><b><u>Adhérent</u></b></td>
<td bgcolor='#669999'><b><u>Montant</u></b></td>
<td bgcolor='#669999'><b><u>Anterieur à 2008</u></b></td>
<td bgcolor='#669999'><b><u>2008</u></b></td>
<td bgcolor='#669999'><b><u>2009</u></b></td>
<td bgcolor='#669999'><b><u>2010</u></b></td>
<td bgcolor='#669999'><b><u>-1 mois</u></b></td>
<td bgcolor='#669999'><b><u>Vérif</u></b></td>";
$total = 0;
if(isset($_POST["frm_select_region"]) AND $_POST["frm_select_region"] != NULL)
{
$var = $_POST["frm_select_region"];
$rqt2 = mysql_query("SELECT * FROM societe WHERE nom_region = '$var' ORDER BY societe")or die(mysql_error());
}
else
{
$rqt2 = mysql_query("SELECT * FROM societe ORDER BY societe")or die(mysql_error());
}
echo("Région selectionnée : $var </br></br>");
if(mysql_num_rows($rqt2) > 0)
{
while($tableau2 = mysql_fetch_array($rqt2))
{
$id = $tableau2['id_numero'];
$societe = $tableau2['societe'];
$adherent = $tableau2['adherent'];
$ville = $tableau2['ville'];
$region = $tableau2['nom_region'];
$enseigne = $tableau2['enseigne'];
$telephone = $tableau2['telephone'];
$fax = $tableau2['fax'];
$siret = $tableau2['siret'];
$rqt = mysql_query("SELECT * FROM facture WHERE id_numero = '$id' ORDER BY `id_numero`")or die(mysql_error());
$ant08 = 0; //ici l'initialisation des variables par année//
$a08 = 0;
$a09 = 0;
$a10 = 0;
$a_1 = 0;
$annee= "";
//ici initialisation des variables total pour chaque année//
$Tant08 = 0;
$Ta08 = 0;
$Ta09 = 0;
$Ta10 = 0;
$Ta_1 = 0; //c'est pour les facture datant d'un - d'un mois ($Ta_1)//
$Tmont_2 = 0; // sert a la totalisation des lignes
$Tmont_3 = 0; // sert à la totalisation de la colonne des totaux
$mont = 0;
while($tableau = mysql_fetch_array($rqt))
{
//calcul par année//
if($tableau['annee'] < 2008)
{
$ant08 += addslashes($tableau['montant']);
}
if($tableau['annee'] == 2008)
{
$a08 += addslashes($tableau['montant']);
}
if($tableau['annee'] == 2009)
{
$a09 += addslashes($tableau['montant']);
}
if($tableau['annee'] == 2010)
{
$a10 += addslashes($tableau['montant']);
}
if($tableau['annee'] == 20101)
{
$a_1 += addslashes($tableau['montant']);
}
//fin du calcul par année//
$mont += addslashes($tableau['montant']);
$Tmont_2 = ($ant08 + $a08 + $a09 + $a10 + $a_1); // totalisation de la ligne //
}
$total += $mont; //calcul du total par année//
$Tant08 += $ant08;
$Ta08 += $a08;
$Ta09 += $a09;
$Ta10 += $a10;
$Ta_1 += $a_1;
$Tmont_3 += $Tmont_2; // Totalisation de la colonne //
if($mont > 0)
{
$ligne .= "<tr>
<td><a href='../includes/relance_02.php?numero=$id' target='_self'>".$id."</a></td>
<td>".$societe."</td>
<td>".$adherent."</td>
<td align='right' bgcolor='#669999'>".$mont."</td>
<td align='right'>".$ant08."</td>
<td align='right'>".$a08."</td>
<td align='right'>".$a09."</td>
<td align='right'>".$a10."</td>
<td align='right'>".$a_1."</td>
<td align='right' bgcolor='#669999'>".$Tmont_2."</td></tr>"; // total de la ligne //
}
}
$ligne .= "<tr><td colspan='3' bgcolor='#669999'>Total Final</td><td align='right' bgcolor='#669999'>".$total."</td>";
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'>".$Tant08."</td>";
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'>".$Ta08."</td>";
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'>".$Ta09."</td>";
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'>".$Ta10."</td>";
$ligne .= "<td colspan='1' align='right' bgcolor='#669999'>".$Ta_1."</td>"; // concerne les factures de moins d'un mois //
$ligne .= "<td colspan='9' align='right' bgcolor='#669999'>".$Tmont_3."</td></tr>"; // total des differents totaux //
$ligne .= "</table>";
}
echo ("$ligne </br>");
mysql_close();
?> |
Merci de votre aide car la je galère
Runcafre91