query($goalquery)) $goal = $r-6ren">
gpt4 book ai didi

php - 使用格式显示来自查询的多个值

转载 作者:行者123 更新时间:2023-11-29 05:24:03 26 4
gpt4 key购买 nike

这是我当前的代码

$goalquery = "SELECT goal FROM Goals";

if ($result = $mysqli->query($goalquery))
$goal = $result->fetch_row();

foreach($goal as $value){
?> My goal is <?php echo $value;
}

它显示 enter image description here

但它应该为 $goal 返回至少 3 个值

应该说...

My goal is to hang my clothing
My goal is to drink less coffee
My goal is to go to the gym everyday

最佳答案

我认为您可能想要 fetch associations 而不是获取行

$goal = $result->fetch_assoc();

来自文档

  • Returns an associative array that corresponds to the fetched row or NULL if there are no more rows.

fecth_row()你使用的函数只会返回一行

  • Fetches one row of data from the result set and returns it as an enumerated array, where each column is stored in an array offset starting from 0 (zero). Each subsequent call to this function will return the next row within the result set, or NULL if there are no more rows.

关于php - 使用格式显示来自查询的多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22263596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com