bonjour,

J'ai un tableau comme ceci, je souhaite avoir une somme de mes colonnes par département mais je suis un peu débutante et je n'arrive pas à faire la somme des mes colonnes;
Le but s'est d'avoir une ligne par département et de faire la somme de tous les montants prévue du département.

voici mon code pouvez m'apporter des solutions.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="icon" type="image/ico" href="favicon.ico">
 </head>
 
<body>
 
 <div align="center"> <h1>    Liste TOTALE </h1></div>
<?php
 
$link= @mysql_connect("") or die("Le site est temporairement saturé de visiteurs!<BR><BR>Nous vous prions de nous excuser pour la gêne occasionnée.</BODY></HTML>");
	mysql_query ("SET NAMES 'iso-8859-1'"); 
	@mysql_select_db("") or die("Echec de sélection de la base. <BR><BR>Veuillez nous excuser pour la gêne occasionnée.</BODY></HTML>");
 
$annee = '2010';
//$annee = $_GET['annee'];
$table1="ETS";  // Nom de la table1
$table2="CONT_ETS";  // Nom de la table2
 
echo "<table align=center width=80% border=1px background-color=#f2e3c4>";
	$html="<tr>";
    $html.="
	<td width=5%>CODE ETS</td>
	<td width=5%>CODE POSTAL</td>
	<td width=15%>PREVU</td>
	<td width=15%>VERSEMENT</td>
	<td width=15%>SOLDE</td>
	
	
	</tr>";  	
echo $html;
 
 
$sql="SELECT * FROM $table1,$table2 WHERE $table2.code_ets = $table1.code_ets AND $table1.cp LIKE '21%' AND annee=".$annee;
$rs =mysql_query($sql);
 
while ($ligne=mysql_fetch_array($rs,MYSQL_ASSOC))
{
	$code_ets  		= $ligne['code_ets'];
	$cp				= $ligne['cp'];
	$prevu  		= $ligne['prevu'];
	$versement  	= $ligne['versement1']+$ligne['versement2'];
	$solde			=$ligne['prevu']-($ligne['versement1']+$ligne['versement2']);
	$nb++;
    echo "<table align=center width=80% border=1px background-color=#f2e3c4>";
	$html="<tr>";
    $html.="

	<td width=5%>$code_ets</td>
	<td width=5%>$cp[0]$cp[1]</td>
	<td width=15%>$prevu</td>
	<td width=15%>$versement</td>
	<td width=15%>$solde</td>
	
	</tr>";
 
 
echo $html;
echo "</table>\n";
}
 
 
?>
</body>
</html>
Merci de votre aide