I'm trying to build a pagination app however my code keeps failing and I don't know why. It works when I replace the LIMIT variables with numbers but not with variables in the query.
$pageNum = $_GET['page'];
$id = $_GET['id'];
if ($pageNum == NULL) {
$pageNum = 1;
}
include("config.php");
include("header.php");
$numPosts = $connect->query("SELECT * FROM forum_posts WHERE category='" . $id . "' ORDER BY latestReply ASC");
$numPosts = $numPost->num_rows;
$resultsPerPage = 10;
$lastPage = ceil($numPosts/$resultsPerPage);
if (!(isset($pagenum))){
$pageNum = 1;
}
if ($pagenum < 1) {
$pageNum = 1;
} elseif ($pageNum > $lastPage) {
$pageNum = $lastPage;
}
$limit1 = $pageNum * $resultsPerPage - $resultsPerPage;
$limit2 = $limit1 + $resultsPerPage;
$post = $connect->query("SELECT * FROM forum_posts LIMIT $limt1, $limit2 WHERE category='" . $id . "' ORDER BY latestReply ASC");
I keep getting this error however:
[17-Nov-2013 17:12:22 Europe/London] PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/robbiewi/public_html/forum/category.php on line 59
On this line:
while ($posts = mysqli_fetch_array($post)) {
All help is much appreciated!