我正在尝试在 PHP 中构建一个简单的分页。但由于某种原因,它一直在输出错误。我似乎无法找到问题所在。这是我的代码:
PHP:
include_once('connect.php'); // connect to db is successful
$count_query = mysql_query("SELECT NULL FROM users");
$count = mysql_num_rows($count_query);
// pagination starts here
if (isset($_GET['page'])) {
$page = preg_replace("#[^0-9]#", "", $_GET['page']);
} else {
$page = 1;
}
$perPage = 5;
$lastPage = cell($count / $perPage);
if ($page < 1) {
$page = 1;
} else if ($page > $lastPage) {
$page = $lastPage;
}
$limit = "LIMIT " . ($page - 1) * $perPage . ", $perPage";
$query = mysql_query('SELECT first_name FROM users ORDER BY user_id DESC $limit');
if ($lastPage != 1) {
if ($page != $lastPage) {
$next = $page + 1;
$pagination .= '<a href="index.php?page=' . $next . '">Next</a>';
}
if ($page != $lastPage) {
$prev = $page - 1;
$pagination .= '<a href="index.php?page=' . $prev . '">Previous</a>';
}
}
while ($row = mysql_fetch_array($query)) {
$output .= $row['first_name'] . '<hr />';
}
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Pagination</title>
</head>
<body>
<h1>My Pagination</a>
<?php echo $output; ?>
<?php echo $pagination; ?>
</body>
</html>
正如标题中所说,我得到了一个"Fatal error: Call to undefined function cell()"
. 我花了几个小时修复,仍然没有运气。我希望你们弄清楚,让我知道是什么问题。