Jump to content

Customizing Pagination Output


srinivas6203

Recommended Posts

My question is: I have the Pagination working beautifully, my only complaint is that in the future when there are a lot of submissions, it will display as

 

[First] [Prev] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [Next] [Last]

 

Which is ok, but I would much rather it show up like Google results, by which I mean only lists a few pages in front of the current page. Like so

 

[First] [Prev] 1 2 3 4 5 6 7 8 9 [Next] [Last]

 

and if you are on page 4

 

[First] [Prev] 4 5 6 7 8 9 10 11 12 [Next] [Last]

 

Unfortunatly for me, I have an idea how I could get this to work, but have not been able to get it right.

 

How would this be done?

 

Here is the code I have right now:

 

if ($pageNum > 1)

{

$page = $pageNum - 1;

$prev = " <a href=\"$self?page=$page\"><img src='Images/Prev.jpg' border='0' /></a> ";

 

$first = " <a href=\"$self?page=1\"><img src='Images/First.jpg' border='0' /></a> ";

}

else

{

$prev = ' '; // we're on page one, don't print previous link

$first = ' '; // nor the first page link

}

 

if ($pageNum < $maxPage)

{

$page = $pageNum + 1;

$next = " <a href=\"$self?page=$page\"><img src='Images/Next.jpg' border='0' /></a> ";

 

$last = " <a href=\"$self?page=$maxPage\"><img src='Images/Last.jpg' border='0' /></a> ";

}

else

{

$next = ' '; // we're on the last page, don't print next link

$last = ' '; // nor the last page link

}

 

// print the navigation link

echo "<table width='500' border='0' cellspacing='0' cellpadding='0'><tr><td width='100' height='50'>" . $first . "</td><td width='75' height='50'>" . $prev . "</td><td width='150' height='50'>" . $nav . "</td><td width='75' height='50'>" . $next . "</td><td width='100' height='50'>" . $last . "</td></tr></table><br>";

}

}

Link to comment
Share on other sites

Try this:

 

<?php
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\"><img src='Images/Prev.jpg' border='0' />[/url] ";

$first = " <a href=\"$self?page=1\"><img src='Images/First.jpg' border='0' />[/url] ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}

if ($pageNum < $pageNum+9)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\"><img src='Images/Next.jpg' border='0' />[/url] ";

$last = " <a href=\"$self?page=$maxPage\"><img src='Images/Last.jpg' border='0' />[/url] ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}

// print the navigation link
echo "<table width='500' border='0' cellspacing='0' cellpadding='0'><tr><td width='100' height='50'>" . $first . "</td><td width='75' height='50'>" . $prev . "</td><td width='150' height='50'>" . $nav . "</td><td width='75' height='50'>" . $next . "</td><td width='100' height='50'>" . $last . "</td></tr></table>
";
}
}
?>

Link to comment
Share on other sites

not tested , but something like this...

$intPagesShown = 10;

if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\"><img src='Images/Prev.jpg' border='0' />[/url] ";
$firstnum = $pageNum -  $intPagesShown /2;
if($firstnum < 1) $firstnum = 1;
$first = " <a href=\"$self?page=".$firstnum."\"><img src='Images/First.jpg' border='0' />[/url] ";
}
else
{
$firstnum = 1;
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}

if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\"><img src='Images/Next.jpg' border='0' />[/url] ";
$lastnum = $firstnum + $intPagesShown - 1;
if($lastnum > $maxPage) $lastnum = $maxPage;
$last = " <a href=\"$self?page=$lastnum\"><img src='Images/Last.jpg' border='0' />[/url] ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}

// print the navigation link
echo "<table width='500' border='0' cellspacing='0' cellpadding='0'><tr><td width='100' height='50'>" . $first . "</td><td width='75' height='50'>" . $prev . "</td><td width='150' height='50'>" . $nav . "</td><td width='75' height='50'>" . $next . "</td><td width='100' height='50'>" . $last . "</td></tr></table>
";
}
}

Link to comment
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.