Re: mysql_numrows
| From: | CC Zona | Date: | Mon, 06 Aug 2001 13:51:03 +0000 |
| Subject: | Re: mysql_numrows | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-61417@lists.php.net to get a copy of this message | ||
In article <Pine.OSF.3.91.1010806142332.22209D-100000@leofric>,
abrandic@coventry.ac.uk (Ajdin Brandic) wrote:
> I'm trying to get number of rows from a query. All works fine until
> the result is 0. Then query executes fine, returns 0 rows but mysql_numrows
> failes.
>
> $query="select * from mytable";
> $result=mysql_query($query) or die("select failed");
mysql_query() returns a result set identifier if the *query was valid*
(regardless of whether any rows were returned) or else false if the query
was not valid. So the line above is "If $query is valid, assign the result
set identifier to $result; but if $query was not valid, die with this
message..." This is different from your next line:
$num_rows=mysql_numrows($result) or die("select count failed");
mysql_num_rows() returns the number of rows in the result set. So this
line is "If $query found *one or more* rows, assign the row count to
$num_rows; but if $query found *zero* rows, die with this message..."
See how they differ? (Drop the second "or die..." if you want the script
to continue even where no rows were returned.)
--
CC