So, you basically want a pagination script? There are several floating around the internet as well as some here on DD. Take a look at the following script to see if that suits your needs:
Code:
<?php
include('dbconnect.php');
// If page is set
if($_GET['page'] && is_numeric($_GET['page'])) {
$page = $_GET['page'];
}
// Set default page
else {
$page = 1;
}
// Max results per page
$max = 7;
// Current page
$cur = (($page * $max) - $max);
// Get data
$qry = mysql_query("SELECT * FROM `test`");
$total = mysql_num_rows($qry); // count results
// Get amount of pages
$total_pages = ($total / $max);
// Is page # more than one
if($page > 1) {
$prev = ($page - 1);
$prevLink = '<a href="?p='.$p.'&page='.$prev.'"><<Previous</a>';
}
// For each page less than total pages
for($i=1;$i<$total_pages+1;$i++) {
// If page = current page
if($page == $i) {
$nav .= ' <b>'.$i.'</b> ';
} else {
// Echo link to previous page
$nav .= ' <a href="?p='.$p.'&page='.$i.'">'.$i.'</a> ';
}
}
// If page is less than total pages, show next link
if($page < $total_pages) {
$next = ($page + 1);
$nextLink = '<a href="?p='.$p.'&page='.$next.'">Next>></a>';
}
########## End Pagination Script ##########
$info = mysql_query("SELECT * FROM `test` LIMIT $cur, $max");
while($row = mysql_fetch_array($info)) {
echo $row['val'].'
<br />';
}
if ($total_pages > 1) {
echo 'Pages: '.$prevLink . $nav . $nextLink;
}
?>
If not, then you may want to look at http://www.php-mysql-tutorial.com/php-mysql-paging.php and view their tutorial.
Hope this helps.
Bookmarks