SQL:带有Zero的Unix时间戳条目

时间:2014-03-26 17:59:25

标签: php mysql

我误解了为什么我的查询给了我一个0的时间戳。谁能说我做错了什么?

查询:

SELECT
    *
FROM
    `changes`
WHERE
        `time_from`>=1393628400
    AND
        `time_to`<=1394838000
    AND
        `area`='USERNAME'
ORDER BY
    `time_from` DESC,
    `time_to` DESC

PHP

$time_from  = (isset($_POST['time_from']) ? strtotime($_POST['time_from']) : null);
$time_to    = (isset($_POST['time_to']) ? strtotime($_POST['time_to']) : null);

if(empty($time_from) && empty($time_to)) {
    /* Do Nothing */
} else {
    if(!empty($time_from) && $time_from > 0 && !empty($time_to) && $time_to > 0) {
        $query  = sprintf(' `time_from`>=%d AND `time_to`<=%d', $time_from, $time_to);
    } else if(!empty($time_from) && $time_from > 0) {
        $query  = sprintf(' `time_from`>=%d', $time_from);
    } else if(!empty($time_to) && $time_to > 0) {
        $query  = sprintf(' `time_to`<=%d', $time_to);
    }

    $results        = $wpdb->get_row(sprintf('SELECT COUNT(*) AS `count` FROM `%sarea_changes` WHERE%s AND `area`=\'%s\'', $wpdb->prefix, $query, $user->user_login));
    $count          = $results->count;

    if($count < 10) {
        $position       = 0;
        $has_more_pages = false;
    }

    $pages          = ceil($count / $max_rows);
    $query          = sprintf('SELECT * FROM `%sarea_changes` WHERE%s AND `area`=\'%s\' ORDER BY `time_from` DESC, `time_to` DESC', $wpdb->prefix, $query, $user->user_login, $position, $max_rows);
    print $query;
    $entrys         = $wpdb->get_results($query); // LIMIT %d, %d
}

POST数据:

time_from01.03.2014time_to15.03.2014

但是我接受了以下的推文(请参阅time_to),为什么0与我的查询不匹配?

截图: (隐私政策的隐藏数据) enter image description here

0 个答案:

没有答案