A Simple Next Page Code
| From: | mike@stratabase | Date: | Thu, 17 Feb 2000 07:22:45 +0000 |
| Subject: | A Simple Next Page Code | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-10404@lists.php.net to get a copy of this message | ||
I tried to create a simplified code for adding a next page link on your site,here it is, it seemed
to workl create for me, so give it a try, if you find any problems with it let me know asap!
<?
// -- connect to database --- //
$hostname = "host";
$username = "username";
$dbName = "database";
MYSQL_CONNECT($hostname,$username,$password) OR DIE("Unable to connect to database");
@mysql_select_db("$dbName") or die("Unable to select database");
// -- set offset to equal the offset from the value coming from the previous next page or to zero if
coming to this page for the first time. -- //
if (!isset($offset)) {
$offset = 0; }
// -- query database, set offset -- //
$query = mysql_query ("select * from table limit $offset, 10;");
$number = MYSQL_NUMROWS($query);
while ($results = mysql_fetch_array($query)){
display your results
// -- this will send a message to the user telling them that there are no articles when the while
loop reaches only 1 more result -- //
if ($number < 0){ echo "there are no more results to view";}
}
// -- since we are using the mysql limit function, if the variable $offset is 0 we must add 11 to it
the first time so that it will increment properly because the limit function uses 0 as the first
entry, if we are getting offset from the previous page the we only have to add 10 to it -- //
if ($offset == 0){
$offset = ($offset + 11);}
else {
$offset = ($offset + 10);}
file://-- this link will set offset for the next page -- //
echo "<a href=\"editorial.php?offset=$offset\">next 10
articles</a>";?>
Godspeed
Mikey T