gpt4 book ai didi

php - 使用 mysqli_fetch_assoc() 从查询填充数组

转载 作者:行者123 更新时间:2023-11-29 13:32:21 24 4
gpt4 key购买 nike

我有这个,一切都工作正常(我有一个通用的表生成器,但现在我不得不偏离它):

 while ($x = mysqli_fetch_assoc($result))
{
$fields[] = $x['Field'];
}

现在我有类似的东西:

 $result = mysqli_query($con, 'SELECT r.id AS ID, CONCAT(g.fname, g.lname) AS Name, r.apple AS Apple, 
r.dog AS Dog, DATEDIFF(r.Dog, r.Apple) AS Days,
r.total_price AS "Total Price", u.name AS Name, r.in AS "In",
r.out AS "Out", r.time_in AS "Time In", r.time_out AS "Time Out",
CONCAT(c.fname,c.lname) AS Charlie, r.here AS "Apple",
r.leave AS "Dog"
FROM really r, georgia g, unit u, charlie c
WHERE g.id = r.georgia AND r.unit = u.id AND r.charlie = c.id
HAVING r.in = TRUE AND r.out = FALSE');

//fill fields array with fields from table in database
while ($x = mysqli_fetch_assoc($result))
{
$fields[] = $x['Field'];
}

由于 Field 一词,我现在收到 $fields[] = $x['Field']; 行错误。为什么?因为我现在有一个完整的查询?如何在不引用每个字段名称的情况下解决此问题?

最佳答案

因为您的查询结果中没有名为Field的字段:

'SELECT r.id AS ID, CONCAT(g.fname, g.lname) AS Name, r.apple AS Apple, 
r.dog AS Dog, DATEDIFF(r.Dog, r.Apple) AS Days,
r.total_price AS "Total Price", u.name AS Name, r.in AS "In",
r.out AS "Out", r.time_in AS "Time In", r.time_out AS "Time Out",
CONCAT(c.fname,c.lname) AS Charlie, r.here AS "Apple",
r.leave AS "Dog"
FROM really r, georgia g, unit u, charlie c
WHERE g.id = r.georgia AND r.unit = u.id AND r.charlie = c.id
HAVING r.in = TRUE AND r.out = FALSE'

您的查询结果中有一些字段:IDNameApple等。您可以尝试获取这些字段如下,或更改您的查询命令。

while ($x = mysqli_fetch_assoc($result))
{
$fields[] = $x['ID'];
}

关于php - 使用 mysqli_fetch_assoc() 从查询填充数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19238116/

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