mois et chiffres dans un tableau
Posté : 02 avr. 2014, 16:29
Bonjour à tous.
Je désire créer un tableau faisant afficher mois par mois le C.A enregistré dans ma table.
J'utilise la requête
Et pour faire apparaitre:
Jusque la, tout fonctionne nickel.
Mais je ne suis pas sur que ce soit la meilleure façon de faire. cela fait beaucoup de requetes à mon gout.
Quelqu'un a une idée?
Merci de votre future aide
Je désire créer un tableau faisant afficher mois par mois le C.A enregistré dans ma table.
J'utilise la requête
$sql1 = 'SELECT SUM(ttc) FROM contacts WHERE YEAR(date_vente) = 2014 AND MONTH(date_vente) = 1';
$req1 = mysql_query($sql1) or die('Erreur SQL !<br />'.$sql1.'<br />'.mysql_error());
$data1 = mysql_fetch_array($req1);
$sql2 = 'SELECT SUM(ttc) FROM contacts WHERE YEAR(date_vente) = 2014 AND MONTH(date_vente) = 2';
$req2 = mysql_query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
$data2 = mysql_fetch_array($req2);
$sql3 = 'SELECT SUM(ttc) FROM contacts WHERE YEAR(date_vente) = 2014 AND MONTH(date_vente) = 3';
$req3 = mysql_query($sql3) or die('Erreur SQL !<br />'.$sql3.'<br />'.mysql_error());
$data3 = mysql_fetch_array($req3);
etc...
pour récupérer les données.Et pour faire apparaitre:
<table>
<thead>
<tr>
<th></th>
<th>Janv</th>
<th>Fevr</th>
<th>Mars</th>
<th>Avr</th>
<th>Mai</th>
<th>Juin</th>
<th>Juil</th>
<th>Août</th>
<th>Sept</th>
<th>Oct</th>
<th>Nov</th>
<th>Dec</th>
</tr>
</thead>
<tbody>
<tr>
<th>Marc</th>
<td><?php echo $data1[0];?></td>
<td><?php echo $data2[0];?></td>
<td><?php echo $data3[0];?></td>
<td><?php echo $data4[0];?></td>
<td><?php echo $data5[0];?></td>
<td><?php echo $data6[0];?></td>
<td><?php echo $data7[0];?></td>
<td><?php echo $data8[0];?></td>
<td><?php echo $data9[0];?></td>
<td><?php echo $data10[0];?></td>
<td><?php echo $data11[0];?></td>
<td><?php echo $data12[0];?></td>
</tr>
</tbody>
</table>
Jusque la, tout fonctionne nickel.
Mais je ne suis pas sur que ce soit la meilleure façon de faire. cela fait beaucoup de requetes à mon gout.
Quelqu'un a une idée?
Merci de votre future aide