-1
$count = mysql_query("SELECT COUNT(id) FROM users");

echo $count;

This is not working . Error message Resource id Unknown #21.
how to fix this ?

2
  • What database are you using? Commented Jan 31, 2014 at 13:18
  • Try this: var_dump($count). Maybe it helps. Commented Jan 31, 2014 at 13:19

2 Answers 2

7

You should use fetchColumn()

$count = $db->query("SELECT COUNT(id) FROM users");

Should be

$count = $db->query("SELECT COUNT(id) FROM users")->fetchColumn();

echo $count; //Returns number of rows
Sign up to request clarification or add additional context in comments.

1 Comment

i am not using PDO. Msql connection is used.
-1

use this mysql_num_rows

$sql=mysql_query("SELECT COUNT(id) FROM users");
$count= mysql_num_rows($sql);
echo $count ;


1 Comment

This answer is wrong as it will return 1 every time it is called

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.