这个问题已经在这里有一个答案:
我有,我有麻烦我的数据库列。
列被命名为Actual
和表看起来像这样
我需要它来阅读这个样子。 [129.74,130.74,129.50]
任何帮助表示赞赏
我曾尝试
测试1
$sth = $db->prepare("SELECT Actual FROM csvhoejde1");
$sth->execute();
/* Fetch all of the remaining rows in the result set */
$result = $sth->fetchAll();
echo'<pre>';
print_r($result);
echo'</pre>';
?>
print_r的结果:
Array
(
[0] => Array
(
[Actual] => 129.74
[0] => 129.74
)
[1] => Array
(
[Actual] => 130.74
[0] => 130.74
)
测试2
<?php
$sql = "SELECT `Actual` FROM `csvhoejde1`";
$test = $db->query($sql)->fetchAll(PDO::FETCH_COLUMN);
echo'<pre>';
print_r($test);
echo'</pre>';
?>
结果:
致命错误:未捕获的错误:调用一个成员函数使用fetchall()阵列上
$upit = "SELECT Actual FROM csvhoejde1";
$conn = new mysqli('localhost','user','pass','db');
$result = $conn->query($upit);
$array = [];
while ($r = mysqli_fetch_assoc($result)){
$array[] = $r;
}
$string = "[";
foreach ($array as $ar){
$string .= $ar['Actual'].",";
}
$string = rtrim($string,',')."]";
echo $string;