0

Below is the resultset of a Query. How can I print out the column names User,UserID and place?

print_r($report_results);

$report_results is the object shown below

Array (
        [0] => stdClass Object ( [User] => Helton, Joshua [UserID] => 31 [place] => Dallas) 
        [1] => stdClass Object ( [User] => Miller, Jona [UserID] => 95 [place] => Cupertino)
        [2] => stdClass Object ( [User] => Sarah, Thomson [UserID] => 32 [place] => Las Vegas)
    )
1
  • 2
    Please please learn just the basics how to access an array and a object! Commented Apr 2, 2015 at 18:44

1 Answer 1

1

Use object access notation, -> as in

var_dump($stdObj->User, $stdObj->UserID, $stdObj->place);

What you have dumped is an array, though, so you'll have to access elements within the array:

var_dump($array[0]->User);

You probably just want to iterate over the array.

foreach ($user as $array) {
    var_dump($user->User, $user->UserID, $user->place);
}
Sign up to request clarification or add additional context in comments.

9 Comments

I don't want their values..I am trying to get the column names from resultset since I am working in creating a table for displaying data which would have dynamic column names as per the query..
@Learner2011 Have you tried something to get the names?
@Learner2011 in that case it would be better for your query response to return an array with keys of the column names rather than a stdClass object
@ExplosionPills Could you please give an example as how?
@Learner2011 I would have to see the code that generates the array of objects in your question.
|

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.