我一直试图在一周内按意见栏排序获得一张桌子的前10条记录。但每次我尝试它将返回最近两三天的最高记录。这是代码
public function TopNewPosts($cat_id = null)
{
$where = "";
if(!is_null($cat_id))
$where = " where postha.`cat_id` = '".$cat_id."'";
$sql = "select postha.`id` as post_id, postha.`title`, postha.`time`,
postha.`cat_id`, postha.`views`,
postha.`likes`, postha.`img` as post_img, `post_cats`.`img` as cat_img,
`post_cats`.`name` as cat_name from
(select * from `posts` where `posts`.`time` > ".time()."-604800 order by
`time` desc limit 10) as postha
inner join `post_cats` on postha.`cat_id` = `post_cats`.`id`
$where
order by `views` desc";
$query = $this->conn->query($sql);
return $query->fetchAll(PDO::FETCH_ASSOC);
}
这是表格架构
id int(11)NO PRI auto_increment
title varchar(255)没有
文字龙文字没有
time varchar(15)没有
cat_id int(11)没有
views int(11)没有
喜欢int(11)没有
img varchar(20)NO default.png