【发布时间】:2011-06-01 06:45:54
【问题描述】:
现在,我在列中使用 php 时间戳 (time()) 作为时间戳。我使用它是因为我认为将它存储为整数比使用日期时间更有效。
现在我在选择两个时间戳之间的时间时遇到了严重的问题。
例如,我正在尝试获取昨天添加的记录(即在 php 时间戳中的今天日期和 todaysdate - php 时间戳中的 24 小时之间)
在sql伪代码中是这样的
SELECT * FROM table
WHERE date < phptimestamp(todaysdate) AND date > phptimestamp(todaysdate -24h)
它确实给我带来了一些记录,但由于某种原因,此范围之间的记录不断变化。我正在查看的时间戳是静态的。这些时间戳之间的记录不应更改,因为添加的所有记录都有当前时间戳。
真实代码
$date = getdate();
$m = time() - (5 * 60);
$h = time() - (($date['minutes'] * 60) + $date['seconds']);
$d = time() - ((60 * 60 * $date['hours']) + ($date['minutes'] * 60) + $date['seconds']);
$y = time() - ((60 * 60 * 24) + ($date['hours'] * 60 * 60) + ($date['minutes'] * 60) + $date['seconds']);
$crawledm = mysql_fetch_assoc(mysql_query("SELECT count(crawled) as count FROM domains WHERE crawled != '' AND crawled > '{$m}'"));
$crawledm = $crawledm['count'];
$crawledh = mysql_fetch_assoc(mysql_query("SELECT count(crawled) as count FROM domains WHERE crawled != '' AND crawled > '{$h}'"));
$crawledh = $crawledh['count'];
$crawledd = mysql_fetch_assoc(mysql_query("SELECT count(crawled) as count FROM domains WHERE crawled != '' AND crawled > '{$d}'"));
$crawledd = $crawledd['count'];
$crawledy = mysql_fetch_assoc(mysql_query("SELECT count(crawled) as count FROM domains WHERE crawled != '' AND crawled > '{$y}' AND crawled < '{$d}'"));
$crawledy = $crawledy['count'];
【问题讨论】:
-
需要更多代码来全面分析(PHP 调用这个 mysql 等...)...真实代码比伪代码好 10 倍。