【发布时间】:2018-02-08 21:19:55
【问题描述】:
我尝试使用数据库迭代创建分页。这是我目前的代码。
$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 个在..中给出。
谁能帮我解决这个错误。
【问题讨论】:
-
在查询中使用
LIMIT start, count进行分页。 -
另外,考虑使用
while($row = $result->fetch_assoc()) -
但我想通过'for'循环来完成。否则分页将不起作用
-
您似乎正在尝试使用
mysqli_fetch_array()替代mysql_result()。见stackoverflow.com/questions/2089590/…
标签: php for-loop mysqli pagination