In article <Pine.OSF.3.91.1010806142332.22209D-100000@leofric>,
 [EMAIL PROTECTED] (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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to