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"

-----Original Message-----
From: Clive Bruton [mailto:[EMAIL PROTECTED]]
Sent: Sunday, July 14, 2002 2:50 PM
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:

          $db = mysql_connect("host", "pass");


          $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.


-- Clive

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to