|
| this is a system i developed last year - it's very simple next previous
just reedit for your use of course
<?
include('../connect.php');
// pagination set up - i want 10 entries per page - first get tally
$limit=10;
$numresults=mysql_query("SELECT * FROM some_table ");
$numrows=mysql_num_rows($numresults);
// next determine if offset has been passed to script, if not use 0
$offset = $_GET['offset'];
if (empty($offset))
$offset=0;
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// go get all the data - use pageination
$qry= mysql_query("SELECT * FROM some_table ORDER BY something LIMIT $offset,$limit");
?>
<html>
<head>
<title>Title here</title>
</head>
<body>
<p>Lists of products here</p>
<?
// this loops through all the products
while($data=mysql_fetch_assoc($qry)){
$price = $data['price'];
$prod = $data['prod'];
$itemID = $data['itemID'];
echo "$prod <a href='order.php?pid=$itemID'>$$price</a><br />";
}
echo "<br />";
// PREV link keep parenthesis
if ((($offset/$limit)>=1)) {
$newoffset=$offset-$limit;
echo "<a href='".$_SERVER['PHP_SELF']."?offset=$newoffset'>prev</a> \n";
}
// NEXT link keep parenthesis
if ( ($offset+$limit)<$numrows OR $offset==0) {
$newoffset=$offset+$limit;
echo "<a href='".$_SERVER['PHP_SELF']."?offset=$newoffset'>next</a>\n";
}
?>
<p><a title="Home" href="index.php">Home</a></p>
<p>For support, text the word HELP to blah blah blah.</p>
</body>
</html>
this will show ten items at a time and the next and prev links appears at the bottom of the page
when you click on them the page refrehes and gets the new set of data with new links to the newer
set of data. This is simple and it works
for the first set of item no previous link shows
for the next few sets both prev and next appears
when you reach near the end of the total set the next will not appear (only the prev) will appear
no sense having next when you reach the end.
read through it and get the logic in your head
i made lots of comments to follow
|
|