0

The users table that I have contains 0 users, with rows userid, firstname and lastname. When I execute this query, I get: (10, mysql result). Shouldn't this return boolean false since there are no users in the table?

$count = mysql_query("SELECT userid FROM users WHERE userid = '$userid' AND trash = '0' ORDER BY DATETIME DESC");

var_dump($count);

I'm just trying to find the count of total users in the table.

diesel
  • 3,337
  • 4
  • 20
  • 16
  • Side note: You are not doing any error checking in your query. You *need* to do that after a `mysql_query()` call. Otherwise, your script will break if the query fails. How to do this is outlined in the [manual on `mysql_query()`](http://php.net/mysql_query) or in this [reference question.](http://stackoverflow.com/questions/6198104/reference-what-is-a-perfect-code-sample-using-the-mysql-extension) – Pekka Dec 15 '11 at 10:44

1 Answers1

2

mysql_query returns a resource, not an array. You should use the mysql_num_rows function for this.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
hoppa
  • 3,011
  • 18
  • 21