0

I had this and everything worked fine (I had a generic table builder, but now I am having to stray from that):

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

Now I have something similar to this:

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

I am now getting an error for the line $fields[] = $x['Field']; because of the word Field. Why? Because I now have a full query? How can I fix this without referencing each field name?

1
  • 1
    why not use mysqli_fetch_array? Commented Oct 8, 2013 at 2:34

1 Answer 1

1

Because there is not a field named Field in you query result:

'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'

There are some fields in your query result: ID, Name, Apple, etc.. You can try to fetch the these field as below, or change your query command.

while ($x = mysqli_fetch_assoc($result))
{
    $fields[] = $x['ID'];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.