我尝试使用数据库迭代创建分页。到目前为止,这是我的代码。
$per_page = 5;
$result = mysqli_query($connection,"SELECT * FROM inquiries");
$total_records = mysqli_num_rows($result);
$total_pages = ceil($total_records / $per_page);
if (isset($_GET['page'])) {
$show_page = $_GET['page'];
if ($show_page > 0 && $show_page <= $total_pages) {
$start = ($show_page - 1) * $per_page;
$end = $start + $per_page;
} else {
$start = 0;
$end = $per_page;
}
} else {
$start = 0;
$end = $per_page;
}
$page = intval($_GET['page']);
$tpages=$total_pages;
if ($page <= 0)
$page = 1;
for ($i = $start; $i < $end; $i++) {
if ($i == $total_records) {
break;
}
echo mysqli_fetch_array($result,$i,'message');
这。因为它会产生跟随错误。
警告:mysqli_fetch_array()最多需要2个参数,其中3个为..
有人可以帮我解决这个错误。
答案 0 :(得分:1)
您可以首先查询SQL_CALC_FOUND_ROWS
,然后SELECT FOUND_ROWS();
作为总计数。
SELECT SQL_CALC_FOUND_ROWS, Id, Name FROM my_table WHERE <give your condition> LIMIT 0, 10;
# Find total rows
SELECT FOUND_ROWS();