Currently the system is set up in the following format:
[PREV] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [NEXT]
And here is the php code that generates this output:
Code: Select all
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("masscic");
//determine the number of records to be displayed per page
$per_page = 5;
//variable in order to declare a starting point
$records = (isset($_GET['records']) ? $_GET['records'] : NULL);
//Count the records in the database
$record_count = mysql_num_rows(mysql_query("SELECT * FROM articles"));
//if the mysql_paginationtest2.php page is found through a search engine set the starting point as below
if (!$records) {
$records = 0;
}
//set up articles page navigation
$prev = $records - $per_page;
$next = $records + $per_page;
if (!($records <=0)) { //show previous button but shows nothing if on the first page
//declare variable and echo below to html page
echo '<li><a href="mysql_paginationtest2.php?records='.$prev.'">Prev</a></li>';
}
//set variable for first page and show page numbers in a for loop
$i = 1;
for ($x=0; $x < $record_count; $x=$x + $per_page)
{
//set current page activation to show user current page status
if ($records!=$x)
echo '<li><a href="mysql_paginationtest2.php?records='.$x.'">'.$i.'</a></li>';
else
echo '<li><a href="mysql_paginationtest2.php?records='.$x.'"class="active">'.$i.'</a></li>';
$i++;
}
if (!($records >=$record_count - $per_page)) {//show next button but show nothing if on the last page
//declare variable and echo below to html page
echo '<li><a href="mysql_paginationtest2.php?records='.$next.'"> Next</a></li>';
}
?>
[PREV] [1] [2] [3] [4] [5] ... [200] [NEXT]
Is there anything I can add to the above code to achieve this?
Thanks for any help.
Gerry