我想从数据库中找到某些项目的数量。我使用了这段代码
$sql=" SELECT count(*) from request WHERE status = '0'";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_assoc($result))
{
echo "<pre>";
print_r($row);
echo "</pre>";
}
}
我在一行中得到这个数组
Array
(
[count(1)] => 1
)
为了从这个数组中获取值,我使用了
$total = $row[0];
echo $total;
但没有得到任何结果。我怎样才能从这个数组中获取值
最佳答案
你需要使用:
$row = mysqli_fetch_row($result);
echo $row[0];
或将您的查询更改为:
$sql=" SELECT count(*) as `num` from request WHERE status = '0'";
并使用:
$row = mysqli_fetch_assoc($result));
echo $row['num'];
关于php - 从数据库中查找数据的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31132091/