# Table structure for table `counter`
#
CREATE TABLE `counter` (
`id` tinyint(4) NOT NULL default '1',
`total` bigint(20) unsigned NOT NULL default '0',
`yesterday` int(10) unsigned NOT NULL default '0',
`today` int(10) unsigned NOT NULL default '0',
`date` date default NULL
) TYPE=MyISAM;
#
# Dumping data for table `counter`
#
INSERT INTO `counter` VALUES (1, 0, 0, 0, NOW());
//اطلاعات لازم براي اتصال به پايگاه داده
$db_user="username";
$db_pass="password";
$db_name="MyDB";
//اتصال به پايگاه داده
$con=mysql_connect('localhost',$db_user,$db_pass);
mysql_select_db($db_name,$con);
//دريافت نتايج از جدول
$result=mysql_query("SELECT * FROM counter");
$row=mysql_fetch_array($result);
$total=$row['total'];
$yesterday=$row['yesterday'];
$today=$row['today'];
$date=$row['date'];
list($year,$month,$day)=split('-',$date);
$CurrentDate=date("Y-m-d");
list($CurrentYear,$CurrentMonth,$CurrentDay)=split('-',$CurrentDate);
//تابع به روزرساني جدول
function Update($today,$yesterday,$total,$date){
mysql_query("UPDATE counter SET today='$today',yesterday='$yesterday',total='$total' ,date='$date' WHERE id=1");
}
//مقايسه تاريخ جاري با تاريخ ذخيره شده در جدول و انجام محاسبات لازم
$total++;
if($CurrentYear==$year){
if($CurrentMonth==$month){
if($CurrentDay==$day){
$today++;
Update($today,$yesterday,$total,$CurrentDate);
}else{
if($CurrentDay==++$day){
$yesterday=$today;
$today=1;
Update($today,$yesterday,$total,$CurrentDate);
}else{
$yesterday=0;
$today=1;
Update($today,$yesterday,$total,$CurrentDate);
}
}
}else{
if($CurrentMonth==++$month){
$yesterday=$today;
$today=1;
Update($today,$yesterday,$total,$CurrentDate);
}else{
$yesterday=0;
$today=1;
Update($today,$yesterday,$total,$CurrentDate);
}
}
}
else{
if($CurrentYear==++$year){
$yesterday=$today;
$today=1;
Update($today,$yesterday,$total,$CurrentDate);
}
else{
$yesterday=0;
$today=1;
Update($today,$yesterday,$total,$CurrentDate);
}
}
//بازيابي مجدد اطلاعات از جدول
$result=mysql_query("SELECT * FROM counter");
$row=mysql_fetch_array($result);
$total=$row['total'];
$yesterday=$row['yesterday'];
$today=$row['today'];
//نمايش شمارنده
echo "today:<strong>$today</strong><br>";
echo"yesterday: <strong> $yesterday</strong><br>";
echo"total:<strong> $total</strong>";
<?php
include_once("counter.php");
?>