GlenR GlenR - 2 years ago 78
SQL Question

mysqli_num_rows is always 1

Can anyone tell me why this

$pages_query = mysqli_query($link, "SELECT COUNT(`id`) FROM `gallery`") or
$row = mysqli_num_rows($pages_query);
echo $row;

echos 1 even though there are 7 rows in my table?

Answer Source

That's because mysqli_num_rows() will return rows count :) and your query will return only one row (with count field).


$result = mysqli_fetch_array($pages_query, MYSQLI_NUM);

to get that count.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download