基于日,周,月重置基础上的跟踪代码

时间:2014-09-23 07:55:08

标签: php

我正在尝试创建一个跟踪代码,当用户进入我的页面时,我将记录并添加访问者视图1

我的代码问题出在每个星期一,不仅重置周统计数据,还重置月份统计信息,我粘贴增量代码并重置代码在php下面。

感谢您帮助我,我试着弄清楚几天,但无法找到我错误编码的位置。

这是我通过do

运行的ads.php
<img src="ads.php" width="1" height="1">
每页

这是我的ads.php代码

include 'conn.php';

$postID = $_GET['pid'];

$todayDate = date("m-d-y");

//Query with postDate

$sql = "SELECT * FROM wp_tracker WHERE postID LIKE '" . $postID . "'";
$result = mysql_query($sql);
$exist = 0;

while ($row = mysql_fetch_array($result)) {
    $postDate = $row['postDate'];
    $dayView = $row['dayView'];
    $weekView = $row['weekView'];
    $monthlyView = $row['monthlyView'];
    $exist++;
}


if ($exist == 0) {
//create new record
    $sql = "INSERT INTO wp_tracker (postID, postDate) VALUES ('$postID ','$todayDate')";

    if (!mysql_query($sql, $con)) {
        die('Error: ' . mysql_error());
    }
}

if ($exist > 0) {
//if record exist
//check if it same day

    if ($postDate == $todayDate) {
//if same day - just increment views
        $dayView = $dayView + 1;
        $weekView = $weekView + 1;
        $monthlyView = $monthlyView + 1;

        $sql2 = "UPDATE wp_tracker SET dayView = '$dayView',weekView = '$weekView',monthlyView = '$monthlyView' WHERE postID='$postID '";
        $result2 = mysql_query($sql2);
    }
}//end if exist

以下是我的重置代码(reset.php)

$todayDate = date("m-d-y");

//Query with postDate

$sql = "SELECT postDate FROM wp_tracker order by postDate ASC";
$result = mysql_query($sql);

$row = mysql_fetch_row($result);

$postDate = $row[0];
$timestamp = time();

if ($postDate != $todayDate) {
    //a new day -- update dayView to 0
    $dayView = 1;
    $sql3 = "UPDATE wp_tracker SET postDate= '" . $todayDate . "', dayView = '$dayView'";
    $result3 = mysql_query($sql3);
}

if (date('D', $timestamp) === 'Mon') {
    $weekView = 1;
    $sql3 = "UPDATE wp_tracker SET weekView = '$weekView'";
    $result3 = mysql_query($sql3);
}


if (date('d', $timestamp) === '01') {
    $monthlyView = 1;
    $sql3 = "UPDATE wp_tracker SET monthlyView= '$monthlyView'";
    $result3 = mysql_query($sql3);
}

0 个答案:

没有答案