You are on the right track with LIMIT.  Simply pass your current location in
a variable in the URL.  Then compute where you next wish to read from.

Assume the following script is initially called with this URL:
http://www.myserver.com/this_script.php3

<?php
...make database server connection ...
...open database...

if ( ! ISSET($loc) ) { $loc=0; $next=1; }
elseif( $next == 1 ) {$loc +=50;}
else ($loc -= 50;}
If ($loc < 0 ) {$loc = 0;}

$query="SELECT field1,filed2,field3,field4 FROM mytable WHERE some_condition
LIMIT $loc,50";
$result = mysql_query($query) or die("Error:".mysql_error());

... do some processing and display of data records ...

\\display PREVIOUS and NEXT links
print "<A href=\"this_script.php3?loc=$loc&next=0\">Previous</A>";
print "<A href=\"this_script.php3?loc=$loc&next=1\">Next</A>";
?>

The first time the script is called, $LOC and $NEXT will have no values, so
they are initialized with 0 and 1 respectively.
Each call thereafter, $LOC has the current location in the database and
$NEXT is set to read forward or behind in the database.
You may also change the script to include a third parameter, the number of
records to be displayed; make thi user-selectable.

-----Original Message-----
From: Shahmat Dahlan [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 07, 2001 2:32 AM
To: PHP Mailing List
Subject: [PHP-DB] Displaying long list in pages


I was trying to list out some records from a MySQL db. And since there
my search result returned to many results, I would like to divide them
into separate pages. I tried to divide results with maybe 50 to 100
lines per page with the "limit" option into my select statement. I can't
somehow figure it out as it didn't work (that well), does some out there
have any idea how I can effectively achieve this?

Appreciate it. Thanks.

e.g.

field 1    field 2    field 3    field 4
......       ........     ..........    .......
......       ........     ..........    .......
......       data here ........    .......
......       ........     ..........    .......
......       ........     ..........    .......

page 1 page 2 page 3 page


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to