mark110384 Posted October 16, 2008 Share Posted October 16, 2008 I'm currently trying to implement pagination into my web forum but it just doesn't seem to work. Currently a user selects a thread to view and the results are displayed as topics. The topics displayed refer to the thread selected, so for example thread 5 with bring back all the topics with the thread id 5 stored along side it. So I would imagine I would have to send the thread_id (throught the url) every time a page selected. Below are snippets of the code. $thread_no = $_GET["thread_selected"]; if (!(isset($pageno))) { $pageno = 1; } $sql_count_pag = "SELECT * FROM forum_topic WHERE thread_ID = '$thread_no'"; $result_pag_count = mysql_query($sql_count_pag) or die ("Data not found"); $numrows = mysql_num_rows($result_pag_count); $rows_per_page = 5; $lastpage = ceil($numrows/$rows_per_page); if ($pageno < 1) { $pageno = 1; } elseif ($pageno > $lastpage) { $pageno = $lastpage; } $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $sql = "SELECT * FROM forum_topic WHERE thread_ID = '$thread_no' ORDER BY last_update DESC $limit"; And the navigation echo " ( Page $pageno of $lastpage ) "; if ($pageno == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?thread_selected=$thread_no&pagenum=1'> <<-First</a> "; echo " "; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?thread_selected=$thread_no&pagenum=$prevpage'> <-Previous</a> "; } if ($pageno == $lastpage) { } else { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?thread_selected=$thread_no&pagenum=$nextpage'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?thread_selected=$thread_no&pagenum=$lastpage'>Last ->></a> "; At the moment the results remain the same in the table but the pagenum in the url changes to 2 when you hit next and then if you hit it again does nothing? Any suggestions would be greatly appreciated thank you Quote Link to comment https://forums.phpfreaks.com/topic/128704-solved-pagination-where-am-i-going-wrong/ Share on other sites More sharing options...
MadTechie Posted October 16, 2008 Share Posted October 16, 2008 HUmmm this line gets the thread $sql = "SELECT * FROM forum_topic WHERE thread_ID = '$thread_no' ORDER BY last_update DESC $limit"; but you only use $thread_no + 1 so if you delete a forum topic your get holes (the thread won't exist) i guess this is what your getting now.. may i suggect trying $sql = "SELECT * FROM forum_topic ORDER BY last_update DESC LIMIT $thread_no, 1 i removed you $limit as i don't know what it does ( i could guess ) EDIT: i sould point out that the example above will need tweaking but should give you the basic idea Quote Link to comment https://forums.phpfreaks.com/topic/128704-solved-pagination-where-am-i-going-wrong/#findComment-666986 Share on other sites More sharing options...
mark110384 Posted October 16, 2008 Author Share Posted October 16, 2008 The $limit sets the range to display in the query $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; Quote Link to comment https://forums.phpfreaks.com/topic/128704-solved-pagination-where-am-i-going-wrong/#findComment-666990 Share on other sites More sharing options...
mark110384 Posted October 16, 2008 Author Share Posted October 16, 2008 Hmmm that only brings back one record. $sql = "SELECT * FROM forum_topic ORDER BY last_update DESC LIMIT $thread_no, 1 Quote Link to comment https://forums.phpfreaks.com/topic/128704-solved-pagination-where-am-i-going-wrong/#findComment-666993 Share on other sites More sharing options...
MadTechie Posted October 16, 2008 Share Posted October 16, 2008 Yeah sorry i thought you was show 1 page then the next page (in singles) okay i would kinda need the full code as its very hard to say if your missing something ie the 2nd query is it being performed ? Quote Link to comment https://forums.phpfreaks.com/topic/128704-solved-pagination-where-am-i-going-wrong/#findComment-666998 Share on other sites More sharing options...
.josh Posted October 16, 2008 Share Posted October 16, 2008 I'm seeing you use $pageno everywhere but your links are passing 'pagenum' is there some part of your code that you haven't shown that basically does $pageno = $_GET['pagenum']; ? Quote Link to comment https://forums.phpfreaks.com/topic/128704-solved-pagination-where-am-i-going-wrong/#findComment-666999 Share on other sites More sharing options...
mark110384 Posted October 16, 2008 Author Share Posted October 16, 2008 Crayon Violent you legend for some stupid reason I omited $pageno = $_GET['pagenum'];works now although I'm having an issue with table layout now as it seems to change cell width at will? Quote Link to comment https://forums.phpfreaks.com/topic/128704-solved-pagination-where-am-i-going-wrong/#findComment-667011 Share on other sites More sharing options...
mark110384 Posted October 16, 2008 Author Share Posted October 16, 2008 Everything is sorted now thanks to everyones help Quote Link to comment https://forums.phpfreaks.com/topic/128704-solved-pagination-where-am-i-going-wrong/#findComment-667020 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.