Si oui fait le !! C'est de cette manière qui te permettra de gérer les dates et pas un entier.
De cette manière tu pourras interpréter tes résultats dans un calendrier de ce type :
<?php
// page index.php
function calandar( $year )
{
$result = array();
$datetime = new DateTime( "$year-01-01", new DateTimeZone( 'Europe/Paris' ) );
while( $datetime-> format( 'Y' ) == $year )
{
$y = $datetime-> format( 'Y' );
$m = $datetime-> format( 'n' );
$d = $datetime-> format( 'j' );
$w = str_replace( '0', '7', $datetime-> format( 'w' ) );
$result[$y][$m][$d] = $w ;
$datetime-> add( new DateInterval( 'P1D' ) );
}
return $result ;
}
$array_days = array(
1 => 'lundi',
'mardi',
'mercredi',
'jeudi',
'vendredi',
'samedi',
'dimanche'
);
$array_months = array(
1 => 'Janvier',
'février',
'mars',
'avril',
'mai',
'juin',
'juillet',
'août',
'septembre',
'octobre',
'novembre',
'décembre'
);
$year = date( "Y" );
if( isset( $_GET['year'] ) )
{
$year = $_GET['year'];
}
$calandar = calandar( $year );
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Calendrier</title>
<style>
html{
font-family: verdana;
}
.year{
color: red;
font-size: 55px;
}
.year a{
text-decoration: none;
color: red;
}
.year a:hover{
color: darkred;
}
.year a:visited{
color: red;
}
.months ul{
margin: 0px;
padding: 0px;
padding-top: 10px;
display: block;
list-style-type: none;
}
.months li{
float: left;
padding-right: 10px;
}
.months a{
color: red;
text-decoration: none;
}
.months a:hover{
color: blueviolet;
}
.months a:visited{
color: red;
}
.month{
padding-top: 10px;
padding-bottom: 50px;
clear: both;
}
.month table{
border-collapse: collapse
}
.month td{
border: 1px solid black;
}
.colspan{
border: none;
}
.relative{
height: 100px;
width: 100px;
}
.day{
text-align: center;
font-size: 20px;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script>
jQuery(function($){
$('.month').hide();
$('.month:first').show();
$('.months a:first').addClass('active');
var index = 1 ;
$('.months a').click(function(){
var month = $(this).attr('id').replace('link-','');
if( month !== index ){
$('#month-' + index).hide();
$('#month-' + month).show();
$('.months a').removeClass('active');
$('.months a#link-' + month).addClass('active');
index = month ;
}
return false ;
});
});
</script>
</head>
<body>
<div class="calandar">
<div class="year">
<a href="index.php?year=<?php echo $year - 1 ?>">-</a>
<span><?php echo $year ?></span>
<a href="index.php?year=<?php echo $year + 1 ?>">+</a>
</div>
<div class="months">
<ul>
<?php foreach( $array_months as $id => $month ): ?>
<li><a href="" id="link-<?php echo $id ?>"><?php echo $month ?></a></li>
<?php endforeach ?>
</ul>
</div>
<?php foreach( current( $calandar ) as $m => $days ): ?>
<div class="month" id="month-<?php echo $m ?>">
<table>
<thead>
<tr>
<?php foreach( $array_days as $day ): ?>
<th><?php echo substr( $day, 0, 3 ) ?></th>
<?php endforeach ?>
</tr>
</thead>
<tbody>
<tr>
<?php $end = end( $days ) ?>
<?php foreach( $days as $d => $w ): ?>
<?php if( $d == 1 and $w != 1 ): ?>
<td colspan="<?php echo $w - 1 ?>" class="colspan"></td>
<?php endif ?>
<td>
<div class="relative">
<div class="day"><?php echo $d ?></div>
</div>
</td>
<?php if( $w == 7 ): ?>
</tr><tr>
<?php endif ?>
<?php endforeach ?>
<?php if( $end != 7 ): ?>
<td class="padding" colspan="<?php echo 7 - $end ?>"></td>
<?php endif ?>
</tr>
</tbody>
</table>
</div>
<?php endforeach ?>
</div>
</body>
</html>
visuel :
A partir de la tu n'as plus qu'a inscrire les résultats HC & HP dans l'année $year, le mois $month et le jour $d. D'où l'extrème utilité d'exploiter une valeur TIMESTAMP (AAAA-MM-JJ HH:MM:SS) et pas INT. Tu pourras récupérer l'année, le mois et le jour en les groupant par date avec les fonctions suivantes :
YEAR(),MONTH(),DAY(),DATE().
SELECT
((MAX(conso_HP) - MIN(conso_HP)) / 1000) AS conso_hp,
((MAX(conso-HC) - MIN(conso_HC)) / 1000) AS conso_hc ,
YEAR(timestamp) AS annee,
MONTH(timestamp) AS mois,
DAY(timestamp) AS jour,
FROM calendrier
GROUP BY DATE(timestamp)
Ciao