justAnoob Posted December 30, 2009 Share Posted December 30, 2009 having trouble find last page for pagination. if i'm on the last page, i would like it to not show the "Next" button. Here is the echo for the "next button" if (!(($startrow / $display) == $pages) && $pages != 1) { $next = $startrow + $display; echo '<a href="testing2.php?startrow=' . $next . '">Next</a> '; } $count is my total number of rows from mysql and $display is the number of pics to be displayed on each page and this gets my total number of pages pages = intval($count / $display); This seems so simple, but I cannot get it to work. Quote Link to comment https://forums.phpfreaks.com/topic/186748-last-page-variable/ Share on other sites More sharing options...
Adam Posted December 31, 2009 Share Posted December 31, 2009 Give this a try: if (ceil($startrow/$display) < $pages && $pages != 1) Edit: meant to use ceil() not floor(). Quote Link to comment https://forums.phpfreaks.com/topic/186748-last-page-variable/#findComment-986181 Share on other sites More sharing options...
justAnoob Posted December 31, 2009 Author Share Posted December 31, 2009 Nothing yet This is what I got <?php if (floor($startrow/$display) < $pages && $pages != 1) { echo ''; } else { $next = $startrow + $display; echo '<a href="testing2.php?startrow=' . $next . '">Next</a> '; } ?> This is my $startrow var below $startrow = $_GET['startrow'] ? $_GET['startrow'] : 0; Quote Link to comment https://forums.phpfreaks.com/topic/186748-last-page-variable/#findComment-986183 Share on other sites More sharing options...
Adam Posted December 31, 2009 Share Posted December 31, 2009 I used the wrong function, note the edit Quote Link to comment https://forums.phpfreaks.com/topic/186748-last-page-variable/#findComment-986185 Share on other sites More sharing options...
justAnoob Posted December 31, 2009 Author Share Posted December 31, 2009 I tried ceil and it still echos (nothing) Quote Link to comment https://forums.phpfreaks.com/topic/186748-last-page-variable/#findComment-986186 Share on other sites More sharing options...
Adam Posted December 31, 2009 Share Posted December 31, 2009 Ah you have the logic the wrong way round: if (ceil($startrow/$display) < $pages && $pages != 1) { $next = $startrow + $display; echo '<a href="testing2.php?startrow=' . $next . '">Next</a> '; } Quote Link to comment https://forums.phpfreaks.com/topic/186748-last-page-variable/#findComment-986187 Share on other sites More sharing options...
justAnoob Posted December 31, 2009 Author Share Posted December 31, 2009 Well I tried that also, but it seems I am right back where I started. It does the same as the code I posted in my frist post. The Next button is always there no matter what page your on. I'm looking to have it there, unless your on the last page. Maybe I confused you. Quote Link to comment https://forums.phpfreaks.com/topic/186748-last-page-variable/#findComment-986189 Share on other sites More sharing options...
premiso Posted December 31, 2009 Share Posted December 31, 2009 if ($pages != $startrow) { $next = $startrow + $display; echo '<a href="testing2.php?startrow=' . $next . '">Next</a> '; } Given that $startrow is the current page, that should do it. Quote Link to comment https://forums.phpfreaks.com/topic/186748-last-page-variable/#findComment-986222 Share on other sites More sharing options...
justAnoob Posted December 31, 2009 Author Share Posted December 31, 2009 can't get it to work that way. The example below works, but I'm looking to change the display amount to 10, But I can't figure out what to change the if statement to so it will still work correctyly. <?php $startrow = $_GET['startrow'] ? $_GET['startrow'] : 0; $pages = intval($count / $display); if ($count % $display) { $pages++; } if ($pages > 1) { for ($i=1; $i <= $pages; $i++) { $next = $display * ($i - 1); echo '<a href="testing2.php?startrow=' . $next . '" class="active" > ' . $i . ' </a> '; } } $last = ceil($count / $display); if(! (($last + 6) < $startrow ) && $pages != 1) { $next = $startrow + $display; echo '<a href="testing2.php?startrow=' . $next . '" class="active" >Next >>></a> '; } else { echo '<span class="inactive">Next >>></span>'; } ?> Most of the code is from an example online that I found. Quote Link to comment https://forums.phpfreaks.com/topic/186748-last-page-variable/#findComment-986260 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.