我正在尝试用 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 :调用未定义的函数 cell()”
。
我花了好几个小时修理,但仍然没有运气。我希望你们能解决这个问题,让我知道问题出在哪里。
最佳答案
它告诉你你正在调用一个未定义的函数。你的问题看起来就在这里。
$lastPage = cell($count / $perPage);
你的意思是ceil()
,而不是 cell()
。
简单的拼写错误,是ceiling的缩写。
关于php - 调用未定义的函数 cell(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19611494/