RE: [PHP] count vs mysql_num_rows
| From: | Jay Blanchard | Date: | Mon, 08 Oct 2007 19:59:31 +0000 |
| Subject: | RE: [PHP] count vs mysql_num_rows | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262933@lists.php.net to get a copy of this message | ||
[snip]
> Is this a joke? You are using a LIMIT 1, so your count is always
> going to be 1.
No, its not a joke. The answer is not going to always 1, its going to
be 1 (the value exists in the DB at least once) or 0 (the value
doesn't exist in the DB), that's what I am trying to test for. I
don't need to know how many times something exists, just if it does.
[/snip]
If you just need to know if data exists use the query with limit 1 and
test to see if 1 === $result['count']. I agree with the poster about not
returning all of the rows, it is more efficient to do it this way.