RE: [PHP-DB] Select a subset?
| From: | Gary dot Every at ingramentertainment dot com | Date: | Mon, 15 Jul 2002 14:11:56 +0000 |
| Subject: | RE: [PHP-DB] Select a subset? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-20552@lists.php.net to get a copy of this message | ||
I think the paging function is what you want
SELECT * from table limit 0,10
for the first ten records
SELECT * from table limit 11,20
for the next ten, etc.
Gary Every
Sr. UNIX Administrator
Ingram Entertainment
(615) 287-4876
"Pay It Forward"
mailto:gary.every@ingramentertainment.com
http://accessingram.com
-----Original Message-----
From: Clive Bruton [mailto:clive@indx.co.uk]
Sent: Sunday, July 14, 2002 2:50 PM
To: php-db@lists.php.net
Subject: [PHP-DB] Select a subset?
I'm just starting to play with PHP and MySQL, kind of getting my head
around it, but one thing I'm not getting (right) is delivery of a subset
of the found records from MySQL. ie if 100 are found how do I get records
1-10 (or 11-20...).
What I have so far is:
<?php
$db = mysql_connect("host", "pass");
mysql_select_db("database",$db);
?>
...
<?php
$result = mysql_query("SELECT * FROM table",$db);
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
echo "<table border=1>";
echo "<tr><td>Name</td><td>Position</tr>\n";
while ($myrow = mysql_fetch_row($result)) {
printf("<tr><td>%s %s</td><td>%s</tr>\n",
$myrow[1],
$myrow[2], $myrow[3]);
}
echo "</table>\n";
?>
However, this delivers all 10,000+ rows on one HTML page.
I have worked out how to use "LIMIT" as an SQL command:
$result = mysql_query("SELECT * FROM url LIMIT 10, 10",$db);
ie start at record 10 and show the next 10. But this delivers back "10"
as the $num_rows variable, when I want the total number of rows.
I don't really have to complete two querys to get the appropriate values
do I?
I'm running PHP 4.2.1 on MacOS X 10.1.4.
TIA
-- Clive
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php