Jump to content

Pagination problem


Ashoar

Recommended Posts

I just added a pagination section to my current code by i have a few errors.

It is set to 10 posts per page. After reaching over 10 posts the link for the 2nd page is then displayed, except no posts show up on the second page, no matter how many you post.

 

 

Here is the code

<?php


include "config.php";

$forumid=$_GET[board];

print "<link rel='stylesheet' href='style.css' type='text/css'>";

print "<A href='post.php?board=$forumid'>New Topic</a>";

$postnumber = 10;
if(!isset($_GET['page'])) {

$page = 1;}else {    
$page = (int)$_GET['page'];}
$from = (($page * $postnumber) - $postnumber);

print "
<table class='maintable'>

   <tr class='headline'><td width=15%>Topic</td>
   <td width=5%>Author</td><td width=5%>Replies</td>
   <td width=20%>Last reply</td>
   </tr>
";

$info="SELECT * from post_reply WHERE board='$forumid' AND parentid='0' ORDER BY lastrepliedto DESC LIMIT $from, $postnumber";
$info2=mysql_query($info) or die(mysql_error());

while($info3=mysql_fetch_array($info2))

{

  $info3[title]=strip_tags($info3[title]);

  $info3[author]=strip_tags($info3[author]);


  print "
  <tr class='mainrow'><td><A href='message.php?id=$info3[postid]'>$info3[title]</a></td>
  <td><A href='member_profile.php?username=$info3[author]'>$info3[author]</a></td>
  <td>$info3[numreplies]</td>
  <td>$info3[showtime]<br>Last post by <A href='member_profile.php?username=$info3[lastposter]'>$info3[lastposter]</a></td>
  </tr>
  ";


}
print "</table>";

$results = mysql_fetch_array(mysql_query("SELECT COUNT(*) as num FROM post_reply where parentid='0'"));
$pages = ceil($results['num'] / $postnumber);if ($page > 1) {    $prev = ($page - 1);    

echo "<a href=\"index.php?page=$prev\"><<  Newer</a> ";
}for($i = 1; $i <= $pages; $i++) {    
if ($page == $i) {        
echo "$i ";        }        else {           
echo "<A href='board.php?board=$forumid?page=$i>$i</a> ";        
}}
?>  

 

What have i done wrong?

 

Edit: If i make a post while on the 2nd page, that post then gets added to the second page, but i want it to add to the first page.

Link to comment
https://forums.phpfreaks.com/topic/153369-pagination-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.