Return to my home page
The Devil's boots don't creak.

Welcome Guest!
Login: 
Pass: 
Remember: 
Home
Why become a Member?
Become a Member
Privacy Policy
Random Joke
One-Liners
What's an Extradisambiguator?
View Guestbook
Sign Guestbook
Spammers List
Sudoku Solver
Write a Guestbook!
Threaded Blog
Links Page
Progenitor Page
Offer pages function
View HJTS MDO list
Search HJTS MDO list
  Offer pages function

1  2  3  4  5  6  7  200


Click on a page number in the list above to go to that hypothetical page.
The first number is always Page 1, while the final one is always the final page.

Here is a function that generates the above pages list effect:

<?php
function offerpages($thispage, $leeway, $nopages)
{
	//
	// $thispage = Current page number, between 1 and $nopages
	// $leeway   = Left and right range of page numbers to display
	// $nopages  = Number of pages in all
	//
	$prefix = ""; // For example, you could set this to "P." or "P"
	$php_self = $_SERVER['PHP_SELF'];
	if ($thispage < 1) $thispage = 1; /* Too small - fix by forcing to 1 */
	if ($thispage > $nopages) $thispage = $nopages; /* Too large - fix by forcing final page */
	$page1 = $thispage - $leeway;
	$pagen = $thispage + $leeway;
	if ($page1 < 1)
	{
		$pagen = $pagen - $page1 + 1; /* Adjust top of the range */
		$page1 = 1; /* Force to 1 */
	}
	if ($pagen >= $nopages)
	{
		$page1 = $page1 + $nopages - $pagen;
		$pagen = $nopages;
		if ($page1 < 1) $page1 = 1;
	}
	if ($page1 > 1)
	{
		// Always give the first page
		echo "<a href=\"$php_self?thispage=1\">${prefix}1</a>&nbsp;&nbsp;";
	}
	for ($i = $page1; $i <= $pagen; $i ++)
	{
		if ($i != $thispage)
		{
			// Hyperlink to the next page
			echo "<a href=\"$php_self?thispage=$i\">$prefix$i</a>&nbsp;&nbsp;";
		}
		else
		{
			// Current page: don't hyperlink it
			echo "$prefix$i&nbsp;&nbsp;";
		}
	}
	if ($pagen < $nopages)
	{
		echo "<a href=\"$php_self?thispage=$nopages\">$prefix$nopages</a>";
	}
	echo "<br />\n";
}
?>


Call it as follows:
<?php
$thispage = <current page number>
$leeway = <Number of pages 'left' and 'right' to offer>
$nopages = <Number of pages in total>
offerpages($thispage, $leeway, $nopages);
?>
	

In the example above, a hardcoded call could be as follows:
<?php
$thispage = (isset($_GET['thispage'])) ? $_GET['thispage'] : 1;
offerpages($thispage, 3, 200);
?>
	

Top of this page      Extradisambiguator home      Check out my Original Website
* Page built in 2 milliseconds *