尝试创建分页时,无法获取总记录数 [英] Cant get total amount of records when trying to create pagination

查看:74
本文介绍了尝试创建分页时,无法获取总记录数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图建立一些分页。目前我有实际的分页工作,但我无法获得返回的记录总数(创建包含所有记录所需的页面数量)。我在SQL中收到错误:



'致命错误:未捕获异常'PDOException',消息'SQLSTATE [HY000]:一般错误:1没有这样的功能: SQL_CALC_FOUND_ROWS'



Hi,

Im trying to set up some pagination. Currently I have the actual pagination working but I cannot get the total amount of records returned (to create the amount of pages needed to contain all the records). I am getting an error in the SQL:

'Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 no such function: SQL_CALC_FOUND_ROWS'

$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$perPage = isset($_GET['per-page']) && $_GET['per-page'] <= 20 ? (int)$_GET['per-page'] : 5;
				
$start = ($page > 1) ? ($page * $perPage) - $perPage : 0;
				
$replies = $db->prepare("
SELECT SQL_CALC_FOUND_ROWS (*) FROM replies JOIN profile ON replies.replyBy = profile.username WHERE replyThreadID=:replyThreadID LIMIT {$start}, {$perPage}");
$replies->bindParam(':replyThreadID', $ID);
$replies->execute();
$replies = $replies->fetchAll(PDO::FETCH_ASSOC);
				
$total = $db->query("SELECT FOUND_ROWS() as total");
echo $total;





我按照教程进行操作。



I followed a tutorial and it should work.

推荐答案

page = isset(
page = isset(


_GET [' page'])? (int)
_GET['page']) ? (int)


_GET [' page']:< span class =code-digit> 1 ;
_GET['page'] : 1;


这篇关于尝试创建分页时,无法获取总记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆