我有这个查询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;
;?>
答案 0 :(得分:1)
在这种情况下,您说$total = ['player_total']
,您可能需要$total = $result['player_total']
;
运行此代码,它会让你接近你想要的东西,然后希望你可以完全接受它:
<?php
$con=mysqli_connect("localhost","root","root","mongolwar");
$result = mysqli_query($con,"SELECT * FROM userdata");
mysqli_close($con);
print_r($result);
?>
另外,你应该真正研究准备好的陈述。