我有这个查询 SQL DB 的代码。我想将数组中的值存储为变量,然后 PHP 在页面的其他位置回显。
任何想法我做错了什么?结果只是“数组”。
<?php
$con=mysqli_connect("localhost","root","root","mongolwar");
$result = mysqli_query($con,"SELECT * FROM userdata");
$total = ['player_total'];
mysqli_close($con);
?>
<?php
echo $total;
;?>
我找到了解决方案:
<?php
$con=mysqli_connect("localhost","root","root","mongolwar");
$result = mysqli_query($con,"SELECT * FROM userdata");
while($row = mysqli_fetch_array($result)) {
$total = $row[player_total];
}
mysqli_close($con);
?>
<?php
echo $total;
;?>