Re: Re: limit items per page

From: Date: Mon, 23 Jul 2001 10:27:15 +0000
Subject: Re: Re: limit items per page
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-59173@lists.php.net to get a copy of this message
Here's a Quick & Dirty script that I ran up to get a display of 10 items per page with each click on a hyper-linked page returning a new page .. if you know what I mean. I've even included the headers so that any newbies can see the complete script and not just bits. The theory is that the first sql statement goes and gets the total number of rows for the display. This is then held in a global variable. The second query goes and gets the rows limited by an incrementing number. Simple, huh! <? include("radius.inc"); radius_db_connect(); define ("INITIAL_PAGE",0); $sql="select distinct username from user"; $res=mysql_query($sql) or die ("OK");; $num_rows=mysql_num_rows($res); $j=1; $i=0; function initial_page(){ global $PHP_SELF, $num_rows, $i,$j, $n; $sql="select distinct username from user limit $n, 10"; $res=mysql_query($sql); while($row=mysql_fetch_array($res)){ print $row["username"]."<br>"; } $k=0; while($i <= $num_rows){ print "<a href = '$PHP_SELF?action=0&n=$i'> [$k]&nbsp</a>\n"; $k++; $i+=10; } } switch($action){ case INITIAL_PAGE: initial_page(); break; default: die ("Could not find function number $action"); } ?> On Mon, 23 Jul 2001 21:25, you wrote: > Perhaps I shouldn't have made the assumption that steph was using mysql :) > > "Henrik Hansen" <hh@mailserver.dk> wrote in message > news:u66ckhuoc.fsf@mailserver.dk... > > > james@towntalk.co.uk (James Holloway) wrote: > > > Hi Steph, > > > > > > as the name suggests, use LIMIT ;) > > > > AFAIK it's mysql specific (at least it does not work with mssql) > > > > -- > > Henrik Hansen

« previous php.general (#59173) next »