Código PHP:
<?php
for ($i=0; $i<12; $i++){
$j = 0;
$x = $i+1;
if ($i<9){
$fec1 = date("Y-0$x-01 00:00:00");
$fec2 = date("Y-0$x-31 00:00:00");
$result = mysql_query("SELECT * FROM direc_http WHERE fecha BETWEEN '$fec1' AND '$fec2' Order by 'fecha' DESC") or die ("no se conecto");
while(mysql_fetch_row($result)){
$j++;
}
$a[$i] = $j;
}else{
$fec1 = date("Y-$x-01 00:00:00");
$fec2 = date("Y-$x-31 00:00:00");
$result = mysql_query("SELECT * FROM direc_http WHERE fecha BETWEEN '$fec1' AND '$fec2' Order by 'fecha' DESC") or die ("no se conecto");
while(mysql_fetch_row($result)){
$j++;
}
$a[$i] = $j;
}
}
$datosTabla = array(
array( "Enero", $a[0], "#BDDA4C"),
array( "Febrero", $a[1], "#FF9A68"),
array( "Marzo", $a[2], "#69ABBF"),
array( "Abril", $a[3], "#FFDE68"),
array( "Mayo", $a[4], "#AB6487"),
array( "Junio", $a[5], "#BDDA4C"),
array( "Julio", $a[6], "#FF9A68"),
array( "Agosto", $a[7], "#69ABBF"),
array( "Septiembre", $a[8], "#FFDE68"),
array( "Octubre", $a[9], "#AB6487"),
array( "Noviembre", $a[10], "#BDDA4C"),
array( "Diciembre", $a[11], "#FF9A68")
);
$maximo = 0;
foreach ( $datosTabla as $ElemArray ) { $maximo += $ElemArray[1]; }
?>
<body>
<table width="400" cellspacing="0" cellpadding="2">
<?php
foreach( $datosTabla as $ElemArray ) {
$porcentaje = round((( $ElemArray[1] / $maximo ) * 100),2); //porcentaje
?>
<tr>
<td width="20%"><strong><?php echo( $ElemArray[0] ) ?></strong></td>
<td width="10%"><?php echo( $porcentaje ) ?></td>
<td>
<table width="<?php echo (($porcentaje)/2) ?>%" bgcolor="<?php echo($ElemArray[2]) ?>">
<tr><td> </td></tr>
</table>
</td>
</tr>
<?php
}
?>