Hvorfor tæller den ikke automatisk ?
Eller er måske i databasen der er en fejl ?
Jeg håber nogen kan hjælpe mig.
<?php
include("../includes/setup.php");
if(!$_SESSION['login']=="ok")
{
header("location: login.php");
exit;
}
include("includes/header.php");
$obj = new BoxTop("Statistik");
$sql1 = mysql_query("SELECT * FROM stats");
while($r1 = mysql_fetch_array($sql1))
{
$hits = $hits + $r1['hits'];
$pageviews = $pageviews + $r1['pageviews'];
$carviews = $carviews + $r1['carviews'];
$mails = $mails + $r1['mails'];
}
echo "<table cellpadding='5' cellspacing='0' width='100%' class='k2'>";
echo " <tr class='header'>";
echo " <td colspan='6'><small>Samlet opgørelse</small></td>";
echo " </tr>";
echo " <tr>";
echo " <td width='24%'>Besøg</td>";
echo " <td width='24%' align='right'>" . number_format($hits, 0, ",", ".") . "</td>";
echo " <td width='4%'></td>";
echo " <td width='24%'>Sidevisninger</td>";
echo " <td width='24%' align='right'>" . number_format($pageviews, 0, ",", ".") . "</td>";
echo " </tr>";
echo " <tr>";
echo " <td width='23%'>Bilvisninger</td>";
echo " <td width='23%' align='right'>" . number_format($carviews, 0, ",", ".") . "</td>";
echo " <td width='4%'></td>";
echo " <td width='23%'>Modtaget post</td>";
echo " <td width='23%' align='right'>" . number_format($mails, 0, ",", ".") . "</td>";
echo " <td width='4%'></td>";
echo " </tr>";
echo "</table>";
echo "<br />";
$hits = 0; $pageviews = 0; $carviews = 0; $mails = 0;
function FindMonth($month)
{
if($month==1){echo "Januar";}
elseif($month==2){echo "Februar";}
elseif($month==3){echo "Marts";}
elseif($month==4){echo "April";}
elseif($month==5){echo "Maj";}
elseif($month==6){echo "Juni";}
elseif($month==7){echo "Juli";}
elseif($month==8){echo "August";}
elseif($month==9){echo "September";}
elseif($month==10){echo "Oktober";}
elseif($month==11){echo "November";}
elseif($month==12){echo "December";}
}
$sql1 = mysql_query("SELECT hits FROM stats ORDER BY hits DESC LIMIT 1");
$r1 = mysql_fetch_array($sql1);
$maxhits = $r1['hits'];
$sql1 = mysql_query("SELECT pageviews FROM stats ORDER BY pageviews DESC LIMIT 1");
$r1 = mysql_fetch_array($sql1);
$maxpageviews = $r1['pageviews'];
$sql1 = mysql_query("SELECT carviews FROM stats ORDER BY carviews DESC LIMIT 1");
$r1 = mysql_fetch_array($sql1);
$maxcarviews = $r1['carviews'];
$sql1 = mysql_query("SELECT mails FROM stats ORDER BY mails DESC LIMIT 1");
$r1 = mysql_fetch_array($sql1);
$maxmails = $r1['mails'];
$klasse = "k2";
$sql1 = mysql_query("SELECT DISTINCT(year) FROM stats ORDER BY year DESC");
while($r1 = mysql_fetch_array($sql1))
{
echo "<div style='padding:5px;'><b style='font-size:14pt;'>" . $r1['year'] . "</a></div>";
echo "<table cellpadding='5' cellspacing='0' width='100%' border=0>";
$sql2 = mysql_query("SELECT DISTINCT(month) FROM stats WHERE year=" . $r1['year'] . " ORDER BY month DESC");
while($r2 = mysql_fetch_array($sql2))
{
$sql3 = mysql_query("SELECT * FROM stats WHERE month=" . $r2['month']. " AND year=" . $r1['year']);
while($r3 = mysql_fetch_array($sql3))
{
$hits = $hits + $r3['hits'];
$pageviews = $pageviews + $r3['pageviews'];
$carviews = $carviews + $r3['carviews'];
$mails = $mails + $r3['mails'];
}
echo " <tr class='header'>";
echo " <td align='center' width='100'><b>";
FindMonth($r2['month']);
echo "</b></td>";
echo " <td></td>";
echo " </tr>";
echo " <tr>";
echo " <td align='center'><b style='font-size:14pt;'>-</b></td>";
echo " <td>";
echo " <table cellpadding='5' cellspacing='0' width='100%'>";
echo " <tr>";
echo " <td width='24%'><small>Besøg</small></td>";
echo " <td width='24%' align='right'><small>" . number_format($hits, 0, ",", ".") . "</small></td>";
echo " <td width='4%'></td>";
echo " <td width='24%'><small>Sidevisninger</small></td>";
echo " <td width='24%' align='right'><small>" . number_format($pageviews, 0, ",", ".") . "</small></td>";
echo " </tr>";
echo " <tr>";
echo " <td width='23%'><small>Bilvisninger</small></td>";
echo " <td width='23%' align='right'><small>" . number_format($carviews, 0, ",", ".") . "</small></td>";
echo " <td width='4%'></td>";
echo " <td width='23%'><small>Modtaget post</small></td>";
echo " <td width='23%' align='right'><small>" . number_format($mails, 0, ",", ".") . "</small></td>";
echo " <td width='4%'></td>";
echo " </tr>";
echo " </table>";
echo " </td>";
echo " </tr>";
$sql4 = mysql_query("SELECT * FROM stats WHERE month=" . $r2['month'] . " AND year=" . $r1['year'] . " ORDER BY day DESC");
while($r4 = mysql_fetch_array($sql4))
{
if($r4['hits']>0){$hits = $r4['hits'] / $maxhits * 100;}else{$hits = 0;}
if($r4['pageviews']>0){$pageviews = $r4['pageviews'] / $maxpageviews * 100;}else{$pageviews = 0;}
if($r4['carviews']>0){$carviews = $r4['carviews'] / $maxcarviews * 100;}else{$carviews = 0;}
if($r4['mails']>0){$mails = $r4['mails'] / $maxmails * 100;}else{$mails = 0;}
$graph = 8;
echo "<tr class='" . $klasse . "'>";
echo " <td align='center'><b style='font-size:12pt;'>" . $r4['day'] . "</b></td>";
echo " <td>";
echo "<table cellpadding='5' cellspacing='0' width='100%' border=0>";
echo " <tr>";
echo " <td width='120'><small>Besøg</small></td>";
echo " <td width='75' align='right'><small>" . number_format($r4['hits'], 0, ",", ".") . " </small></td>";
echo " <td><img src='images/graph.jpg' height='" . $graph . "px' width='" . number_format($hits, 0, "", "") . "%'></td>";
echo " </tr>";
echo " <tr>";
echo " <td><small>Sidevisninger</small></td>";
echo " <td align='right'><small>" . number_format($r4['pageviews'], 0, ",", ".") . " </small></td>";
echo " <td><img src='images/graph.jpg' height='" . $graph . "px' width='" . number_format($pageviews, 0, "", "") . "%'></td>";
echo " </tr>";
echo " <tr>";
echo " <td><small>Bilvisninger</small></td>";
echo " <td align='right'><small>" . number_format($r4['carviews'], 0, ",", ".") . " </small></td>";
echo " <td><img src='images/graph.jpg' height='" . $graph . "px' width='" . number_format($carviews, 0, "", "") . "%'></td>";
echo " </tr>";
echo " <tr>";
echo " <td><small>Modtaget post</small></td>";
echo " <td align='right'><small>" . number_format($r4['mails'], 0, ",", ".") . " </small></td>";
echo " <td><img src='images/graph.jpg' height='" . $graph . "px' width='" . number_format($mails, 0, "", "") . "%'></td>";
echo " </tr>";
echo "</table>";
echo " </td>";
echo "</tr>";
if($klasse=="k1")
{$klasse = "k2";}
elseif($klasse=="k2")
{$klasse = "k1";}
}
echo "<tr>";
echo " <td> </td>";
echo " <td> </td>";
echo "</tr>";
$hits = 0;
}
echo "</form>";
echo "</table>";
}
$obj = new BoxBottom();
include("includes/footer.php");
?>