Posted by Oli Filth on 09/26/06 11:08
friglob said the following on 26/09/2006 11:09:
> monomaniac21 wrote:
>>
>> How can you get rid of the error that displays if you do a query which
>> returns no result and then try and fetch the array, WITHOUT having to
>> put the while in another conditional like if ($result != ''), something
>> more efficient if possible.
>>
>
> $result = mysql_query($query);
> $num = mysql_num_rows($result);
>
> if( $num ) {
>
> while ($row = mysql_fetch_array($result)){
>
> //whatever
>
> }
> }
But why bother? Both these tests do the same thing. If there are no
results (i.e. no rows returned), then the first call to
mysql_fetch_array() will return false, and the while loop will stop.
--
Oli
[Back to original message]
|