SQL查询无法正确构建

时间:2014-05-27 17:51:10

标签: php mysql

我做了一个查询,显示了5个结果,在一个月内有最高的观看次数; 使用静态日期自己的查询工作正常,但是当我尝试使用date()函数获取当前年份和月份时,它不起作用:

$currentmonth = date("m");
$nextmonth = $currentmonth++;
$gethotbookq = mysqli_query($con,"SELECT BookID, COUNT(*) AS `num` FROM `BOOKS_views` WHERE `TIME` >= '2014- $currentmonth-01 00:00:00' and `TIME` < '2014-$nextmonth-01 00:00:00' GROUP BY `BookID` LIMIT 5") or die();

1 个答案:

答案 0 :(得分:0)

 $currentmonth = date("m");
 $nextmonth    = date("m", strtotime(" +1 month"));
 $gethotbookq  = mysqli_query($con,"SELECT BookID, COUNT(*) AS `num` FROM `BOOKS_views` WHERE `TIME` >= '2014-$currentmonth-01 00:00:00' and `TIME` < '2014-$nextmonth-01 00:00:00' GROUP BY `BookID` LIMIT 5") or die();