liam1412 Posted February 22, 2007 Share Posted February 22, 2007 Hi I have my forum in 2 tables forum_question forum_answer I collect the question and display that, then collect all the replies using a while loop. I have a pagination script for the view_topic part of my forum. I have included an if statement so that if the pageno is not set in the URL then it wil display the question and if it is it won't. the problem is this The first time I open the topic it displays the question then all the answers but then if i browse the the other pages then press back in my pagination then the pageno is the set in the URL so it doesn't dispaly the question. How can I get round this. Does this even make any sense??? Basically if my result set returns 30 rows then it will be on 3 pages. But the question which is the first post only wants to to be on the first page of 3!!!! Any way here is my script!!! <?php //the if statement if(!isset($_GET['pageno'])){ ?> <table class="topic" cellspacing="1"> <tr> <td class="comment_date" colspan="3"> <?php echo $topic_start_datetime; ?> - <?php echo $topic; ?> </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> <?php } $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; $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); ?> <?php 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="post_reply"> <a href="post_reply.php?topic_id=<?php echo $topic_id;?>&forum_id=<?php echo $forum_id;?>">Post reply</a> </div> <div class="pagination_right"> <? 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> "; } ?> </div> </div> <?php if($no_of_views == 99){ $sql_hot_topic = "UPDATE forum_question SET topic_status = $topic_update WHERE topic_id = '$topic_id'"; mysql_query($sql_hot_topic)or die("unable to update topic status"); } $sql_update_topic_view = "UPDATE forum_question SET topic_view = '$topic_view' WHERE topic_id = '$topic_id'"; mysql_query($sql_update_topic_view)or die("failed to update topic_reply"); mysql_close(); ?> <?php include 'footer.php'; ?> Link to comment https://forums.phpfreaks.com/topic/39590-solved-pagination-in-my-forum/ Share on other sites More sharing options...
liam1412 Posted February 22, 2007 Author Share Posted February 22, 2007 Figured Im so dumb sometimes Link to comment https://forums.phpfreaks.com/topic/39590-solved-pagination-in-my-forum/#findComment-191062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.