0

I want to count the number of rows in a table (using PHP and Mysql) all of the count() functions I can find only return columns, or array features, is there a function to return the number of rows? Many thanks!

4 Answers4

0

you can count the number of rows returned by a query. note that this function is deprecated... it has options on the docs page here.

http://ca1.php.net/function.mysql-num-rows

rkstar
  • 1,178
  • 14
  • 27
0

You need to use mysqli_num_rows() :

$con=mysqli_connect("host","name","pass","database");

$sql="SELECT * FROM table_name";
$result=mysqli_query($con, $sql);
$rowcount=mysqli_num_rows($result);

$rowcount now stores the number of rows.

user2397282
  • 3,798
  • 15
  • 48
  • 94
0
$count = mysql_num_rows($query);

would return the number of rows selected by the query, make sure you are not using count() in the query itself.

TLama
  • 75,147
  • 17
  • 214
  • 392
-1

Depending if you are using mysql, mysqli or PDO query.

if mysql_query rkstar told you how to do it :

if mysqli_query : http://php.net/manual/fr/mysqli-stmt.num-rows.php

if PDO : do another query ! $rowCount = $db->query("SELECT FOUND_ROWS()")->fetchColumn();

aviel
  • 178
  • 9