For reference, here's why count()
is returning 1
. From the manual:
If the parameter is not an array or not an object with implemented Countable interface, 1 will be returned. There is one exception, if array_or_countable [the parameter] is NULL, 0 will be returned.
Since $result
is a resource (object) that is returned from your query, not an array which you would get within your loop getting the actual data out of the resource, count($resource)
will return 1
.
Your solution is of course to use mysqli_num_rows()
. To retrieve data from this resource, you need to loop over it as you are doing, but either use mysqli_num_rows()
in place of count()
, or other (more common) ways of looping through a result set, like so:
while($row = mysqli_fetch_row($result)) {
// do stuff
}