I have got that statment:
$result1=mysql_query(" SELECT COUNT(*) FROM users WHERE user_name='$userName'") or exit(mysql_error());
and I want to find the count this way:
if($row=mysql_fetch_array($result1))
{
$userNameResult=$row['COUNT(*)'];
}
I think I am not doing it right? or am I? why do i put count(*) in the statment and in the row variable? why cant I put it once in either? instead of both..is that the way to do it.? is that the best practice
What you are doing works, but it might be better to create a column alias for
COUNT(*)in the query, that you can reference in your fetch call. This is really only a readability improvement.You could achieve the same thing without using a fetch call at all, if you modified your query to select all rows and then use
mysql_num_rows(). Which method is more efficient depends somewhat on the contents of your database.