runnerjp Posted October 24, 2008 Share Posted October 24, 2008 im trying to go to the last page of a topic so i have done this in my links placed pagenum=last and in my message area i have added.. if($pagenum === "last") { $query = "Select COUNT(*) as C from forumtutorial_posts where parentid='$id'"; $result = mysql_query($query); $data = mysql_fetch_array($result); $pagenum = floor($data['C'] / $page_rows) + 1; } it was working great untill have found a floor in it... for some reason if the topic has 3 pages of posts and on each page it holds 5 posts.. when it gets to having 5 out of 5 posts with 2+ pages and the link is clicked for some reason it sends me to 4 out of 3 pages :S any idea why?? Quote Link to comment Share on other sites More sharing options...
Orio Posted October 24, 2008 Share Posted October 24, 2008 That piece of code is familiar... It's like I've written it I don't really understand where you're having problems. Maybe you can post/PM me the link so I could see it? Anyway, for debugging purposes, check the output given by: <?php if($pagenum === "last") { $query = "Select COUNT(*) as C from forumtutorial_posts where parentid='$id'"; $result = mysql_query($query); $data = mysql_fetch_array($result); $pagenum = floor($data['C'] / $page_rows) + 1; die ("Count is: ".$data['C']."<br>page_rows: ".$page_rows."<br>Pagenum: ".$pagenum); } ?> Orio. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 24, 2008 Author Share Posted October 24, 2008 i got this Count is: 12 page_rows: 4 Pagenum: 4 Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 24, 2008 Share Posted October 24, 2008 You should probably only add one if the result is less than one Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 24, 2008 Author Share Posted October 24, 2008 but i am only adding 1 $pagenum = floor($data['C'] / $page_rows) + 1; Quote Link to comment Share on other sites More sharing options...
Orio Posted October 25, 2008 Share Posted October 25, 2008 Try replacing this line: $pagenum = floor($data['C'] / $page_rows) + 1; With: <?php if($data['C'] == 0) $pagenum = 1; else $pagenum = ceil($data['C'] / $page_rows); ?> I hope that will work well. Orio. 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.