09-24-2007, 11:56 PM
|
#2 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
|
Pagination really deserves a whole new tutorial, but I've written this basic one out for you to direct you down the right path. As you can see, I've hard-coded both the array and the $iCount variable, but these will be made up of two MySQL calls in your case:
- SELECT COUNT(*) FROM myTable
- SELECT myColumn1, myColumn2 from myTable.
Respectively.
PHP Code:
aPages = array('Pear', 'Orange', 'Grape', 'Kiwi', 'Mango', 'Red Pitaya', 'Melon', 'Lime', 'Lemon', 'Banana', 'Apple'); $iCount = count($aPages); $iPerPage = 5; $iCurPage = isset($_GET['page']) ? $_GET['page'] : 0;
$iUpper = $iCurPage + $iPerPage;
for($iIndex = $iCurPage; $iIndex < $iUpper; $iIndex++) { if(!isset($aPages[$iIndex])) { break; } echo 'Page: ' . $aPages[$iIndex] . '<br />'; }
if($iCurPage >= $iPerPage) { $iPreviousPage = $iCurPage - $iPerPage; echo '<a href="pag.php?page=' . $iPreviousPage . '">Previous</a> '; }
if($iCount > $iCurPage + $iPerPage) { $iNextPage = $iCurPage + $iPerPage; echo ' <a href="pag.php?page=' . $iNextPage . '">Next</a>'; }
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|