liam1412 Posted February 23, 2007 Share Posted February 23, 2007 Hi basically as above. if there is only one post in the topic selected it offers the option to go back and when clicking it it obviously goes to pageno=-1 which displays nothing but mysql_errors. Can anyone see why <?php //Decide if to display the topic if pageno is not set or set to 1 if(!isset($_GET['pageno']) || ($_GET['pageno'] == 1)){ ?> //display the topic - collected above this but irrelevant to query <table class="topic" cellspacing="1"> <tr> <td class="comment_date" colspan="3"> <?php echo $topic_start_datetime; ?> </td> </tr> <tr> <td class="comment_poster" valign="top"> <a href="view_profile.php?userid=<?php echo $topic_starter_id ; ?>"><?php echo $username;?></a> <br /> <img src="images/profilepics/<?php echo $user_ava; ?>" alt="avatar" border="2"> <br /> <b>Member Since:</b><br /> <?php echo $member_since; ?> <br /> <b>Location:</b><br /> <?php echo $location; ?> </td> <td class="comment_text" valign="top" colspan="2"> <?php echo $text; ?> </td> </tr> </table> //And then I collect the replies from the seperate table <?php }//clsoe the if statement that dictates with to display the topic or not. $limit = 5; if(isset($_GET['pageno'])){ $page_no = $_GET['pageno']; } else { $page_no = 1; } $select = "SELECT * FROM forum_answer WHERE ans_topic_id = $topic_id"; $query = mysql_query($select); $no_rows = mysql_num_rows($query); $rows_per_page = 5; $last_page = ceil($no_rows/$rows_per_page); if($page_no < 1){ $page_no = 1; } elseif ($page_no > $last_page){ $page_no = $last_page; } $page = ($page_no - 1) * $rows_per_page; if($no_rows != 0){ $select = "SELECT * FROM forum_answer WHERE ans_topic_id = $topic_id ORDER BY ans_datetime ASC LIMIT $page,$rows_per_page"; $query = mysql_query($select); while($get_replies = mysql_fetch_array($query)){ $date = $get_replies['ans_datetime']; $poster_id = $get_replies['ans_poster_id']; $text = $get_replies['ans_text']; $text = nl2br($text); $text = BBCODE($text); $poster = "SELECT * FROM users WHERE userid = '$poster_id'"; $poster_query = mysql_query($poster); $poster_array = mysql_fetch_array($poster_query); $username = $poster_array['username']; $member_since = $poster_array['signup_date']; $avatar = $poster_array['avatar']; $location = $poster_array['location']; ?> <table class="forum_reply" cellspacing="1"> <tr> <td class="reply_date" colspan="2"><?php echo $date; ?></td> </tr> <tr> <td class="reply_poster"> <a href="view_profile.php?userid=<?php echo $poster_id ; ?>"><?php echo $username;?></a> <br /> <img src="images/profilepics/<?php echo $avatar; ?>" alt="avatar" border="2"> <br /> <b>Member Since:</b><br /> <?php echo $member_since; ?> <br /> <b>Location:</b><br /> <?php echo $location; ?> </td> <td class="reply" valign="top"><?php echo $text; ?></td> </tr> </table> <?php } } ?> <div class="pagination"> <? if ($page_no == 1) { echo "FIRST PREV"; } else { echo " <a href='{$_SERVER['PHP_SELF']}?topic_id=$topic_id&pageno=1'>FIRST</a> "; $prevpage = ($page_no-1); echo " <a href='{$_SERVER['PHP_SELF']}?topic_id=$topic_id&pageno=$prevpage'>PREV</a> "; } echo " -- $page_no of $last_page -- "; if ($page_no == $last_page) { echo " NEXT LAST "; } else { $nextpage = ($page_no+1); echo " <a href='{$_SERVER['PHP_SELF']}?topic_id=$topic_id&pageno=$nextpage'>NEXT</a> "; echo " <a href='{$_SERVER['PHP_SELF']}?topic_id=$topic_id&pageno=$last_page'>LAST</a> "; } ?> Link to comment https://forums.phpfreaks.com/topic/39727-pagination-screws-up-if-only-one-post-in-topic-any-clues/ Share on other sites More sharing options...
btherl Posted February 23, 2007 Share Posted February 23, 2007 Do your pages start at 0 or 1? If you're getting -1 as your previous page, that indicates that page number is set to 0, but your code assumes that page numbers start at 1. Link to comment https://forums.phpfreaks.com/topic/39727-pagination-screws-up-if-only-one-post-in-topic-any-clues/#findComment-191836 Share on other sites More sharing options...
liam1412 Posted February 23, 2007 Author Share Posted February 23, 2007 When I first open the topic the page number is not set. If that is the only page then the pagination should not show any links but if there is only one post it is showing teh option to go back and it shouldn't. If i press back that's when it goes to minus 1 Link to comment https://forums.phpfreaks.com/topic/39727-pagination-screws-up-if-only-one-post-in-topic-any-clues/#findComment-191845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.