我已经使用phpMyAdmin验证了我的查询。这个数是130。但是我的代码给了我一个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返回行数。您只有1行。该行将包含130。获取结果。

$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);

关于php - PHP MySQL未返回正确的计数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37489852/

10-13 01:23