0

我有这个并且一切正常(我有一个通用的表构建器,但现在我不得不偏离它):

 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'];
    }

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

4

1 回答 1

1

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'];
}
于 2013-10-08T02:42:02.733 回答