Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mySQL>限制相同数量的返回值_Php_Mysql_Pdo - Fatal编程技术网

Php mySQL>限制相同数量的返回值

Php mySQL>限制相同数量的返回值,php,mysql,pdo,Php,Mysql,Pdo,我正在开发内容/评论系统。。 我希望:对于数组中的每个内容,最多返回10条注释。。 我尝试限制20,但这限制了总结果,如何仅限制列comment_id中的重复值 $contentidArray是内容ID的数组 $sthandler = $conn->prepare("SELECT * FROM comments WHERE content_id in (".$contentidArray.") order by total_reactions desc"); $sthandler->

我正在开发内容/评论系统。。 我希望:对于数组中的每个内容,最多返回10条注释。。 我尝试限制20,但这限制了总结果,如何仅限制列comment_id中的重复值

$contentidArray是内容ID的数组

$sthandler = $conn->prepare("SELECT * FROM comments WHERE content_id in (".$contentidArray.") order by total_reactions desc");

$sthandler->execute();

检查此查询的自连接,以获取每个内容id最多10条记录

select c.* FROM comments c
left join comments c1 ON c.content_id = c1.content_id AND c.id <= c1.id
group by c.id
having COUNT(*) <= 10
order by c.content_id, c.id DESC;

那么你想增加10个限制?你面临的问题是什么?谢谢,我现在就试试。。