Hi. Welcome to Bytes!
After trying, and failing, to explain this a few times, I feel a simple code example will be more helpful :)
Consider this:
-
<?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($pageIndex))
-
$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("SELECT field FROM table LIMIT {$firstItem}, {$ammountPerPage}");
-
-
// Show the data
-
// ... for example
-
forech ($row = mysql_fetch_assoc($result)) {
-
echo "Field = ". $row['field'] ." <br />";
-
}
-
-
// Show the Next and Prev links
-
echo "<a href='?pindex={$prevPage}'>Previous {$ammountPerPage}</a> |
-
<a href='?pindex={$nextPage}'>Next {$ammountPerPage}</a>";
-
?>
-
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.