Thursday, 30 August 2018

PHP MySQL does not return the correct number

I have verified my query using phpMyAdmin. The count is 130. But my code is giving me a count of 1.

$query2 = "SELECT COUNT(*) FROM webvulns";
$result2 = mysqli_query($connection, $query2);
confirm_query($result2);
$rowcount=mysqli_num_rows($result2);
echo $rowcount;
// Free result set.
mysqli_free_result($result2);


mysqli_num_rows returns a count of rows. You only have 1 row. That row will have 130in it. Fetch the result.
$query2 = "SELECT COUNT(*) as da_count FROM webvulns";
$result2 = mysqli_query($connection, $query2);
confirm_query($result2);
$row = mysqli_fetch_assoc($result2);
$rowcount=$row['da_count'];
echo $rowcount;
// Free result set.
mysqli_free_result($result2);

0 comments:

Post a Comment