Re: counting records in db
| From: | Paul Novitski | Date: | Thu, 26 Oct 2006 18:44:58 +0000 |
| Subject: | Re: counting records in db | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-243701@lists.php.net to get a copy of this message | ||
At 10/26/2006 11:16 AM, afan@afan.net wrote:
Would it be ok to use the same code to check if customer is loged in?
$query = mysql_query("
SELECT COUNT(Username) as NoOfRecords
FROM customers
WHERE Username = '$Username' AND Password = '$Password'");
if (mysql_result($query, 0) == 0)
I'd question whether you really needed to get a record count. If your logon system is robust, each member will be listed only once; even if not, it's probably not the number of records you're interested in learning but whether or not there are any. I'd suffice with:
SELECT Username
FROM customers
WHERE Username = '$Username' AND Password = '$Password'
LIMIT 1,0;
In a case like this, where I'm confident I have either one record or none, I'd be happy to use mysqsl_num_rows().
In the example above, which field you select is arbitrary, unless you actually want more information about the logged-on user:
SELECT FirstName, LastName, SecurityLevel
FROM customers
WHERE Username = '$Username' AND Password = '$Password'
LIMIT 1,0;
Regards,
Paul