Yes I have built many a forums and product listings/search engines like this..


simply make it check using COUNT how many rows there are total..


now let's say your viewing page 1..

so we can see listing 1 - 10 therefore the first offset is 1

so the next set will logically be 11-20

so with this info:

<?
$page=(isset($HTTP_GET_VARS["page"])?$HTTP_GET_VARS["page"]?1);
$item_count=mysql_fetch_array(mysql_query("SELECT count(*) FROM tablename",$DB));
if($item_count-$page>10) echo "<a href=".$PHP_SELF."?page=".($page+10).">Next Page 
>></a>";
?>


now as you can see I use $HTTP_GET_VARS["page"] here so this means that the page will 
add in the GET var by itself as the user browses around the place..

For extra functionality: (code from before plus some new bits)

<?
$page=(isset($HTTP_GET_VARS["page"])?$HTTP_GET_VARS["page"]?1);
$item_count=mysql_fetch_array(mysql_query("SELECT count(*) FROM tablename",$DB));
if($page>10) echo "<a href=".$PHP_SELF."?page=".($page-10)."><< Previous Page</a>";
if($item_count-$page>10) echo "<a href=".$PHP_SELF."?page=".($page+10).">Next Page 
>></a>";
?>

this simply adds a backward control to the form as well..


from here you can design it as you wish... generally placed in a table on bottom left 
and right, using this same system you can also expand it to create a numerical fast 
page index at the bottom with a listing of available pages (1 2 3 4 5 6) as links etc..


endless possibilities..





okay then... I hope I was able to help someone out here..






:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Julien Bonastre [The-Spectrum.org CEO]
A.K.A. The_RadiX
[EMAIL PROTECTED]
ABN: 64 235 749 494
Mobile: 0407 122 268
QUT Student #: 04475739
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::




----- Original Message ----- 
From: "Jason Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, April 06, 2002 7:25 PM
Subject: Re: [PHP] limit posts and have a next page?


> On Saturday 06 April 2002 16:57, Hawk wrote:
> > This is just speculations, but I thought I'd as well ask now before I get
> > to work
> > Lets say I have a news page, and I only want the last ten posts to show on
> > it, then I ORDER BY id ASC LIMIT 10 right?
> > but how do I add the next page?
> > count rows from the database and see if its more than 10 lines, and then ?
> > saw something about a MAX and a MIN mysql command, but how do I use it? and
> > should I use it for that purpose? :)
> > like... ORDER BY id ASC LIMIT 10 MIN(10) MAX(20) or something?
> > I dont know really.. just speculations as I said :)
> 
> Rather than indulging in idle speculation, consult the mysql manual :)
> 
> For the first 10:
> 
>   ... ORDER BY id ASC LIMIT 0, 10 
> 
> 
> For the next 10:
> 
>   ... ORDER BY id ASC LIMIT 10, 10 
> 
> 
> -- 
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
> 
> /*
> Nothing is so firmly believed as that which we least know.
> -- Michel de Montaigne
> */
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

Reply via email to