background image

CREATE TABLE `mycounter` (
`id` int(11) NOT NULL auto_increment,
`Counter` int(11) NOT NULL,
`CounterLastDay` int(10) default NULL,
`CounterToday` int(10) default NULL,
`RecordDate` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=2 ;
函数
代码如下
<?PHP
public function ShowMyCounter(){
//定义变量
$IsGone = FALSE;
//读取数据
$querysql = "SELECT * FROM `mycounter` WHERE id =  '

Ƈ  ";

$queryset = mysql_query($querysql);
$row = mysql_fetch_array($queryset);
//获得时间量
$DateNow = date('Y-m-d');
$RecordDate = $row['RecordDate'];
$DateNow_explode = explode("-",$DateNow);
$RecordDate_explode = explode("-",$RecordDate);
//判断是否已过去一天
if( $DateNow_explode[0] > $RecordDate_explode[0]) $IsGone = TRUE;
else if( $DateNow_explode[0] == $RecordDate_explode[0] ){
if( $DateNow_explode[1] > $RecordDate_explode[1] ) $IsGone = TRUE;
else if( $DateNow_explode[1] == $RecordDate_explode[1] ){
if( $DateNow_explode[2] > $RecordDate_explode[2] ) $IsGone = TRUE;
}else BREAK;
}else BREAK;
//根据 IsGone 进行相应操作
IF($IsGone) {
$RecordDate = $DateNow;
$CounterToday = 0;
$CounterLastDay = $row['CounterToday'];
$upd_sql  =  "update  mycounter  set  RecordDate  =  '$RecordDate',CounterToday  = 
'$CounterToday',CounterLastDay = '$CounterLastDay' WHERE id =  '

Ƈ  ";

mysql_query($upd_sql);
}
//再次获取数据
$querysql = "SELECT * FROM `mycounter` WHERE id =  '

Ƈ  ";

$queryset = mysql_query($querysql);
$Counter = $row['Counter'];