This question already has an answer here:
- MySQLi count(*) always returns 1 7 answers
I have a table called quote in my database with 5 rows. However when I try to count the rows it always returns 1 instead of 5. I am using the code below:
$connection = mysqli_connect("host","username","password","database");
$querya = "SELECT COUNT(id) FROM quote";
$resulta = mysqli_query($connection, $querya);
$max = mysqli_num_rows($resulta);
$srow = rand(1,$max);
<br /> There are <?php echo $max ?> number of rows
I am counting the id column which is a primary key and therefore never null. I have also tried it by using count(*) but get the same result. Where am I going wrong?
</div>