Le 3000 c'était pour mes tests car en faites je compte utiliser un select pour régler la boucle for comme avec des bornes pour parcourir des années mais c'est vrai que la 3000 c'est beaucoup du coup j'ai réduit le nombre.
Oui j'ai vu qu'il fallait déclarer le tableau avant mais la je me heurte à la même erreur car je suis passé à un tableau a plusieurs dimensions. Car il doit contenir l'année en 1er puis pour chaques année le montant.
tiens voici se que j'ai fait:
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
| public function indexAction()
{
$table_consommation = new Application_Model_Consommation();
$montant = array();
for($i=2014;$i<=2050;$i++){
$montant[] = $i;
for($j=1;$j<=12;$j++){
if($j<=9){
$j = '0'.$j;
}
$select = $table_consommation->select();
$select->from('consommation', array('sum(MONTANT_TOTAL) as montant_total'))
->where('DATE_RELEVE like ?', '%'.$i.'-'.$j.'%');
$res = $table_consommation->fetchAll($select);
// var_dump($res[0]['montant_total']);
if($res[0]['montant_total'] != null){
// echo "<td class='cn_td'>"; echo $consommation->montant_total."";echo "</td>";
//$this->view->montant = $consommation->montant_total;
$montant[$i][] = $res[0]['montant_total'];
}
}
}
$this->view->montant = $montant;
} |
Et la vue pour aussi si tu peux m'aider pour l'affichage:
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
| <div id="depense">
<h1 class='cn_h1' style='margin: 0 10px 10px 10px; padding: 0;'>Dépenses</h1>
<table id='table_depense'>
<tr>
<th class='cn_th'></th>
<th class='cn_th'>Janvier</th>
<th class='cn_th'>Fevrier</th>
<th class='cn_th'>Mars</th>
<th class='cn_th'>Avril</th>
<th class='cn_th'>Mai</th>
<th class='cn_th'>Juin</th>
<th class='cn_th'>Juillet</th>
<th class='cn_th'>Aout</th>
<th class='cn_th'>Septembre</th>
<th class='cn_th'>Octobre</th>
<th class='cn_th'>Novembre</th>
<th class='cn_th'>Decembre</th>
</tr>
<?php
foreach($this->montant as $annee => $montant_mois) { ?>
<tr>
<td class='cn_td'><?php echo $annee;?></td>
<?php
foreach($montant_mois as $montant){ ?>
<td class='cn_td'><?php echo $montant; ?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div> |
EDIT: C'est bon j'ai trouvé la solution et ça fonctionne plutot pas mal:
controller:
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
| public function indexAction()
{
$table_consommation = new Application_Model_Consommation();
$montant = array();
// $montant[]=array();
for($i=2014;$i<=2020;$i++){
// $montant[] = $i;
$montant[$i]=array();
for($j=1;$j<=12;$j++){
if($j<=9){
$j = '0'.$j;
}
$select = $table_consommation->select();
$select->from('consommation', array('sum(MONTANT_TOTAL) as montant_total'))
->where('DATE_RELEVE like ?', '%'.$i.'-'.$j.'%');
$res = $table_consommation->fetchAll($select);
// var_dump($res[0]['montant_total']);
if($res[0]['montant_total'] != null){
// echo "<td class='cn_td'>"; echo $consommation->montant_total."";echo "</td>";
//$this->view->montant = $consommation->montant_total;
$montant[$i][] = $res[0]['montant_total'];
}
}
}
$this->view->montant = $montant;
} |
Et la vue:
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
| <div id="depense">
<h1 class='cn_h1' style='margin: 0 10px 10px 10px; padding: 0;'>Dépenses</h1>
<select name="select_annee" id="select_annee">
<option value="">---</option>
<?php for($i=2010;$i<=2100;$i+=5){
$fin = $i +5;
?>
<option value="<?php echo $i."-".$fin;?>"><?php echo $i."-".$fin;?></option>
<?php }?>
</select>
<table id='table_depense'>
<tr>
<th class='cn_th'></th>
<th class='cn_th'>Janvier</th>
<th class='cn_th'>Fevrier</th>
<th class='cn_th'>Mars</th>
<th class='cn_th'>Avril</th>
<th class='cn_th'>Mai</th>
<th class='cn_th'>Juin</th>
<th class='cn_th'>Juillet</th>
<th class='cn_th'>Aout</th>
<th class='cn_th'>Septembre</th>
<th class='cn_th'>Octobre</th>
<th class='cn_th'>Novembre</th>
<th class='cn_th'>Decembre</th>
</tr>
<?php
$result = count($this->montant);
foreach($this->montant as $annee => $montant_mois) { ?>
<tr>
<td class='cn_td'><?php echo $annee;?></td>
<?php if(!empty($montant_mois)){ ?>
<?php foreach($montant_mois as $montant){ ?>
<?php if($montant != null){?>
<td class='cn_td'><?php echo $montant.""; ?></td>
<?php }
else {?>
<td class='cn_td'><?php echo "0"; ?></td>
<?php } ?>
<?php }
} else {
for($j=1;$j<=12;$j++){ ?>
<td class='cn_td'><?php echo "0"; ?></td>
<?php }
} ?>
</tr>
<?php } ?>
</table>
</div> |
Encore merci pour ton aide!