The COUNT(*)
or query version should be faster because you are not going futher down to mysql_num_rows
. For counting you don't need all fields (*
), you should simply do COUNT(fieldID)
which is a lot faster.
Few Points To Note:
Note that you are getting only one row anyways because you are using where
clause, in other words, the result will be either one row or no row if not found:
$total_points = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM account WHERE id='$id'"),0)
Normally you should count when you are expecting more than one record eg:
$total_points = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM account"),0)
Again, for optimized query, use a single field:
$total_points = mysql_result(mysql_query("SELECT COUNT(fieldID) as Num FROM account"),0)