Im trying to get the amount of elements in an array using the count() function, the result is a bit puzzling to me, considere the following example.
Assume that the user ID provided is wrong, and therefore had no matches, wouldnt then the result of the count function be 0? yet it is 1. can you explain to me why?
thanks
$q = mysql_query("select password from users where user_name = '" . $userID . "'");
$check = mysql_fetch_array($q);
$result = count($check);
echo "RESULT:" . $result;
That’s the wrong way to count rows in a result set. First of all, from the documentation on mysql_fetch_array()
Ergo, if we do this
We can see the output is
1. Why? Because the count() documentation tells us that as wellTo do a proper count, use mysql_num_rows()