simmsy Posted April 27, 2010 Share Posted April 27, 2010 Hi im having some trouble with the pagination of my forum it constantly shows 2 pages to click on but never any more even if i have more to display or have none to display if anyone can help would be great? Heres the code: <?php $url=curPageURL(); //Connect to DB include("connect.php"); // get value of id that sent from address bar $web_id=$_GET['id']; $searchresult=mysql_query("SELECT id, username, title, detail FROM forum_topic WHERE id='$web_id'") or die(mysql_error()); while($row=mysql_fetch_array($searchresult)) { $id = $row['id']; $title = $row['title']; ?> <tr bordercolor="#666666" bgcolor="#FFFFFF"><td width="40" height="34" align="center" bgcolor="#222222"> <font color="#FFFFFF"><b>#<? echo $row['id']; ?></b></font> </td><td width="110" height="34" align="center" bgcolor="#C4C4C4"> <b><? echo $row['username']; ?></b> </td><td width="420" align="center"> <? echo $row['title']; ?> </td></tr> <tr bordercolor="#666666"><td height="34" colspan="3" align="center"> <em><? echo $row['detail']; ?></em> </td></tr> </table> <br /> <div align="center" class="style4"> <table width="302"> <form action="topic_reply.php" method="post"> <tr> <td colspan="2"><div align="center">Topic Reply:</div></td> </tr> <tr> <td width="111"><div align="center">Username</div></td> <td width="175"><input name="username" type="text" id="username" value="<?php echo $user; ?>" readonly="READONLY"/></td> </tr> <tr> <td><div align="center">Reply </div></td> <td><textarea name="reply" rows="5" id="reply"></textarea></td> </tr> <tr> <td colspan="2"><input type="hidden" name="topic_id" value="<?php echo $id; ?>" /></td> </tr> <tr> <td colspan="2"><input type="hidden" name="forumname" value="<?php echo curPageURL(); ?>" /></td> </tr> <tr> <td colspan="2"><input type="hidden" name="topic_title" value="<?php echo $title; ?>" /></td> </tr> <tr> <td height="39" colspan="2"><div align="center"> <input name="submit2" type="submit" id="submit" value="Submit" /> </div></td> </tr> </form> </table> </div> <? } mysql_close(); ?> <br /> <? $var=explode('?id=',$url); $var=explode('&',$var[1]); ?> <table width="546" border="1" align='center' cellpadding="0" cellspacing="0" bordercolor="#666666"> <tr bordercolor="#666666" bgcolor="#222222"><td width="40" height="34" align="center"><font color="#FFFFFF"><b>ID:</b></font></td><td width="110" height="34" align="center"><font color="#FFFFFF"><b>Username:</b></font></td><td width="420" align="center"><font color="#FFFFFF"><b>Reply:</b></font></td></tr> <?php //Connect to DB include("connect.php"); $limit = 5; //Number of results per page $page=$_GET["page"]; //Get the page number to show if($page == "") $page=1; //If no page number is set, the default page is 1 //Get the number of results $searchresult=mysql_query("SELECT * FROM search ORDER BY title") or die(mysql_error()); $numberofresults=mysql_num_rows($searchresult); //Get the number of pages $numberofpages=ceil($numberofresults/$limit); $searchresult=mysql_query("SELECT id, username, reply FROM forum_reply WHERE topic_id='$id' ORDER BY id LIMIT " . ($page-1)*$limit . ",$limit") or die(mysql_error()); while($row=mysql_fetch_array($searchresult)) { ?> <tr bordercolor="#666666"><td width='30' height="34" align='center' bgcolor="#222222"><font color="#FFFFFF"> #<? echo $row['id']; ?> </font></td> <td width='110' align='center' bgcolor="#C4C4C4"> <b><? echo $row['username']; ?>:</b> </td> <td> <em><? echo $row['reply']; ?></em> </td> </tr> <? } mysql_close(); ?> </table> <br /> <div align="center"> <? $nav=""; if($page > 1) { $nav .= "<a href=\"forum-viewtopic.php?id=$var[0]&page=" . ($page-1) ."\"><< Prev</A>"; } for($i = 1 ; $i <= $numberofpages ; $i++) { if($i == $page) { $nav .= "<b>$i</b>"; }else{ $nav .= "<a href=\"forum-viewtopic.php?id=$var[0]&page=" . $i ."\"> $i </A>"; } } if($page < $numberofpages) { $nav .= "<a href=\"forum-viewtopic.php?id=$var[0]&page=" . ($page+1) ."\">Next >></A>"; } Echo "<br><br>" . $nav; ?> </div> <br /> </div> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.