
<?
mysql_pconnect("localhost","username","password");
mysql_select_db("spoono_news");
//initialize the start to 0
if(!$rowstart) $rowstart=0;
//mysql queries
$result = mysql_query("select * from shoutbox limit $rowstart,5");
$result2 = mysql_query("select * from shoutbox");
//find the number of total rows in the shoutbox total
$numrows = mysql_num_rows($result2);
//put all the code here for running the script itself using $result in the while loop
//put where you want the next prev to appear
if ($rowstart > $numrows)
{
echo "<A HREF=\"<? $php_self ?>?rowstart=<? echo $rowstart-5;?>\">< Previous Page </A>
}
if($rowstart+5<$numrows)
{
echo "<A HREF=\"<? $php_self ?>?rowstart=<? echo $rowstart+5;?>\">< Next Page </A>
}
?>
The first two lines connect to the database which you want to use. The next line defines $rowstart if it isn't previously defined. That line is only acceptable on Apache platforms. The first $result variable tells SQL to select from the shoutbox table, but only limit to 5 results from the starting point $rowstart. Now, if you are using the Shoutbox from the shoutbox tutorial, you will need to replace the line:
<? $result = mysql_query("select * from shoutbox order by id desc limit 5"); ?>
with
<? $result = mysql_query("select * from shoutbox order by id desc limit $rowstart,5"); ?>
The $result2 variable just sets it up so we can find the total number of rows in the shoutbox table. The next five lines put the "Previous Page" link on the HTML. It's an if-then statement saying that if it's not the first page, then display the previous page link. That way, if you're on the first page, the previous page link won't show up at all. The | just adds a divider between the previous and next page links. The $numrows calculates the total number of rows in the whole shoutbox database. Finally, the last five or so lines do the same thing as the previous page link, but for the "Next page" links. If you go through the code, it's fairly easy to understand. Copyright © 2000-2008 Spoono, LLC. All rights reserved.
Network: Reseller Web Hosting by Spoono Host | Spoonloads | Absolute Cross
Terms of Service | Privacy Policy.