GlenR GlenR - 7 months ago 12
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
die(mysqli_error($link));
$row = mysqli_num_rows($pages_query);
echo $row;


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

Answer

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

Use

$result = mysqli_fetch_array($pages_query, MYSQLI_NUM);

to get that count.

Comments