Re: counting records in db

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 10/26/2006 11:16 AM, afan@xxxxxxxx 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux