At 01:24 PM 5/30/2002, you wrote:

>Hey guys,
>I have a very simple question, I though I knew the answer but the MySql 
>manual has confused me....
>
>I have a simple select from a database of say.......1k records...I use
>
>select id from myTable where sal>1000;
>
>Lets say this statement would normally return 132 records, but how do I 
>know how many it will return?
>Basically I want it to return
>
>"The query returned 0-20 of 132 records"
>(I am using PHP)
>I know theres a "count" somewhere....but where?
>
>Cheers,
>-Ryan

Ryan,
           You can issue a "select count(*) ..." but that will refetch the 
rows all over again and isn't efficient if you are using it a web server. 
(You're doubling the amount of i/o.) You probably want to use 
mysql_num_rows. Here is an excerpt from the PHP manual.

int mysql_num_rows (resource result)

mysql_num_rows() returns the number of rows in a result set. This command 
is only valid for SELECT
statements. To retrieve the number of rows affected by a INSERT, UPDATE or 
DELETE query, use
mysql_affected_rows().

Example 1. mysql_num_rows() example
<?php
$link = mysql_connect("localhost", "username", "password");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
?>

Mike


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to