0

我有这个查询 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;

;?>
4

1 回答 1

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

?>

此外,您应该真正研究准备好的陈述。

于 2013-10-03T04:25:14.880 回答