I am trying to build a simple pagination in PHP. But for some reason it keeps outputting the error. I just can't seem to find the issue. Here is my code:
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>
As said in the title, i'm getting a "Fatal error: Call to undefined function cell()"
.
I've spent hours of fixing and still no luck. I hope you guys figure it out and let me know what's the problem.
It is telling you that you are calling an undefined function. Your problem looks to be over here.
$lastPage = cell($count / $perPage);
You mean ceil()
, not cell()
.
Simple spelling mistake, it is short for ceiling.