Jump to content

Recommended Posts

I went through both of the tutorials from the main site and neither one of them actually shows enough pages or makes the numbers links.

Can anyone see what's wrong? I get just a number 1 at the bottom and it's not even a link. I have 21 threads and the limit is 10, so I should get at least 3 pages.

<?php
$page = (!isset($_GET["page"])) ? 1 : $_GET["page"];
$max_results = 10;
$from = ($page * $max_results) - $max_results;
dbconnect();
$q = "SELECT COUNT(*) FROM blog_threads";
$r = mysql_query($q);
$total_results = mysql_num_rows($r);
$total_pages = ceil($total_results / $max_results);

$query =  "SELECT * FROM blog_threads ORDER BY lastpostdate DESC LIMIT $from, $max_results";
$result = mysql_query($query) or DIE("Error: getThreads().");
if (mysql_num_rows($result) > 0) {
$c = 0;
echo "<table id=\"threads\" class=\"floatright w_100\" cellspacing=\"0\">";
echo "<tr><th class=\"w_25 topicHeader\">Subject</th><th class=\"w_25 topicHeader\">Started by</th><th class=\"w_25 topicHeader\">Posts</th><th class=\"w_25 topicHeader\">Last post</th></tr>";
while ($r = mysql_fetch_array($result)) {
	$c++;
	$id = $r["id"];
	$title = $r["title"];
	$created = $r["created"];
	$first = getUsername($r["firstposter"]);
	$last = getUsername($r["lastposter"]);
	$posts = getNumPosts($id);
	$datetime = explode(" ", $r["lastpostdate"]);
	$ymd = explode("-", $datetime[0]);
	$lastdate = date("d F Y", mktime(0, 0, 0, $ymd[1], $ymd[2], $ymd[0]))." at ".$datetime[1];
	echo ($c & 1) ? "<tr class=\"white\">\n" : "<tr class=\"bg_gray white\">\n";
	echo "<td><a href=\"showThread.php?id=$id\" title=\"$title\">$title</a></td>";
	echo "<td>$first</td><td>$posts</td><td class=\"smaller\">$lastdate<br />by $last</td>";
	echo "</tr>\n";
}
echo "</table>";

echo "<div id=\"pagination\">";

if ($page > 1){
	$prev = $page - 1;
	echo "<a href=\"".$_SERVER["PHP_SELF"]."?page=$prev\"><<Previous</a> ";
}

for ($i = 1; $i <= $total_pages; $i++){
	if ($page == $i){
		echo "$i ";
	} else {
		echo "<a href=\"".$_SERVER["PHP_SELF"]."?page=$i\">$i</a> ";
	}
}

if ($page < $total_pages){
	$next = $page + 1;
	echo "<a href=\"".$_SERVER["PHP_SELF"]."?page=$next\">Next>></a>";
}
echo "</div>";

} else {
echo "<p>There aren't any threads right now.</p>\n";
}
dbclose();
?>

Link to comment
https://forums.phpfreaks.com/topic/58768-solved-pagination-not-working/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.