0

我正在尝试在 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()". 我花了几个小时修复,仍然没有运气。我希望你们弄清楚,让我知道是什么问题。

4

2 回答 2

4

它告诉你你正在调用一个未定义的函数。你的问题看起来已经结束了。

$lastPage = cell($count / $perPage);

你的意思是ceil(),不是cell()

简单的拼写错误,它是天花板的缩写。

于 2013-10-26T20:23:48.133 回答
0

cell 是 PHP 找不到的函数调用...

您没有在代码中显示它,所以它存在吗?

于 2013-10-26T20:25:13.703 回答