【问题标题】:Call to undefined function cell()调用未定义的函数 cell()
【发布时间】:2013-10-26 20:22:09
【问题描述】:

我正在尝试在 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()"。 我花了几个小时修复,仍然没有运气。我希望你们弄清楚并告诉我问题出在哪里。

【问题讨论】:

  • 那么你在哪里定义名为 cell() 的函数...或者你的意思是ceil()
  • 是的,我的错,我是想在那里写 ceil。我不敢相信它溜走了!谢谢你的回答。

标签: php mysql pagination call


【解决方案1】:

它告诉你你正在调用一个未定义的函数。您的问题似乎已经解决了。

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

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多