<?php

require("dbconfig.php");

function 
query($querydata)
         {
     
$result = @mysql_query($querydata);
     if (
mysql_errno()!=0)
        echo(
"Eroare la interogare MySQL: ".mysql_error());
     return 
$result;
     }

$conn = @mysql_connect($db_host$db_user$db_pass) or die("Eroare la conectare MySQL: ".mysql_error());
mysql_select_db($db) or die("Eroare la selectarea bazei de date: " mysql_error());

function 
counts(){
$result=query("select count(*) as cnt from stattable");
$row mysql_fetch_array($result);
$total_counted $row['cnt'];
echo 
"Numar de vizite ".$total_counted;

$result=query("select count(distinct(remote_ip)) as cnt from stattable");
$row mysql_fetch_array($result);
$unique_counted $row['cnt'];
echo 
"Numar unic de vizitatori ".$unique_counted;
}

function 
last_n($max_number){
//ultimele n intrari in baza de date
$result=query("select date_time, remote_ip, remote_user_agent, remote_referer from stattable order by id desc");

$row=mysql_fetch_array($result);
$number=0;

echo 
"<table cellpadding=0 cellspacing=0 border=0> <tr> <td bgcolor=#000000>";
echo 
"<table border=0 cellspacing=1>\n";
echo 
"<tr><td bgcolor=#ffffff><b>Data</b></td>";
echo 
"<td bgcolor=#ffffff><b>Adresã IP</b></td>";
echo 
"<td bgcolor=#ffffff><b>Date client</b></td>";
echo 
"<td bgcolor=#ffffff><b>Recomandat de:</b></td></tr>";

while(
$row && $number<$max_number)
     {
     echo 
"<tr>";
     echo 
"<td bgcolor=#ffffff>".$row["date_time"]."</td>";
     echo 
"<td bgcolor=#ffffff>".$row["remote_ip"]."</td>";
     echo 
"<td bgcolor=#ffffff>".$row["remote_user_agent"]."</td>";
     echo 
"<td bgcolor=#ffffff>".$row["remote_referer"]."</td>";
     echo 
"</tr>\n";
     
$number++;
     
$row=mysql_fetch_array($result);
     }
echo 
"</table>\n";
echo 
"</td></tr>";
echo 
"</table>\n";
     
}

$number_max=0;
isset(
$_POST['number_max']) && $number_max = (int)$_POST['number_max'];
last_n($number_max);

mysql_close($conn);
?>