RE: [PHP-DB] Displaying long list in pages
| From: | Rick Emery | Date: | Fri, 07 Dec 2001 14:42:49 +0000 |
| Subject: | RE: [PHP-DB] Displaying long list in pages | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-14863@lists.php.net to get a copy of this message | ||
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:shahmatd@sains.com.my]
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: php-db-unsubscribe@lists.php.net
For additional commands, e-mail: php-db-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net