RE: [PHP] test for empty $result??
| From: | Boget, Chris | Date: | Mon, 10 Sep 2001 18:09:21 +0000 |
| Subject: | RE: [PHP] test for empty $result?? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-66794@lists.php.net to get a copy of this message | ||
> Then you can use:
> if (mysql_num_rows($result) == 0) {
> stuff here
> }
> This will check the number of rows returned from your query. If zero,
> then do something....modify as you need.
What I generally do is this:
if(( !$result ) || ( mysql_errno() > 0 )) {
// error code here
}
OR
if(( $result ) && ( mysql_errno() == 0 )) {
// it's all good
}
If you want to use the above, precede the mysql_num_rows() function
call with the "@" symbol. If, for whatever reason, there was an error
or if there was a NULL result, you will get an error on the page saying
that it is an invalid result ID.
Chris