Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/186748-last-page-variable/
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/186748-last-page-variable/#findComment-986183
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/186748-last-page-variable/#findComment-986189
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/186748-last-page-variable/#findComment-986260
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.