After trying, and failing, to explain this a few times, I feel a simple code example will be more helpful :)
Consider this:
[code=php]
<?php
// Get the current page index, sent thought the URL
$pageIndex = @$_GET['pindex'];
// If there was no index in the URL, set it to 0
if(empty($pageI ndex))
$pageIndex = 0;
// Set some basic variables needed throughout the script
$amountPerPage = 10;
$nextPage = $pageIndex + 1; // The number for the Next link
$prevPage = $pageIndex - 1; // The number for the Prev link
$firstItem = $pageIndex * $ammountPerPage ;
// Get the data from where ever you get you data from
// ... compact MySQL example
$result = mysql_query("SE LECT field FROM table LIMIT {$firstItem}, {$ammountPerPag e}");
// Show the data
// ... for example
forech ($row = mysql_fetch_ass oc($result)) {
echo "Field = ". $row['field'] ." <br />";
}
// Show the Next and Prev links
echo "<a href='?pindex={ $prevPage}'>Pre vious {$ammountPerPag e}</a> |
<a href='?pindex={ $nextPage}'>Nex t {$ammountPerPag e}</a>";
?>
[/code]
The index of the page that is to be displayed is simply added to the URL as a GET variable, and then retrieved through the $_GET array. If there is no variable passed the page index will be set to 0 (the first page).
This piece of code is obviously pretty basic and will have to be improved and adjusted to your needs before it is put to use, but you get the idea.
Comment