这是我当前的功能:
$result = $db->sql_query("SELECT * FROM data1,data2,data3,data4 WHERE person='" .$name. "'");
$row = $db->sql_fetchrow($result);
$day = $row['regtime'];
$days = (strtotime(date("Y-m-d")) - strtotime($row['regtime'])) / (60 * 60 * 24);
if($row > 0 && $days < 15){
$row = ['name'];
$row = ['age'];
//etc
但是上面的函数在 regtime
行中进行了双重读取。我正在寻找的是我可以将这两个函数合并到单个查询中吗?如果是的话怎么办?
最佳答案
您是说您只想要结果集中最近 15 天的行吗?
您没有包含如何连接 data1-4 表,并且您的 person
字段对 SQL 注入(inject)开放,因此我将这些部分省略,但下面包含的是方法仅过滤过去 15 天的记录:
SELECT *
FROM data1
WHERE person = :name
AND regtime >= NOW() - INTERVAL 15 DAY
关于php - 如何在单个 mysql 查询中集成日期检查功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3244300/