1

I have coded

foreach($DB->query($query) as $row){
print_r($row);

which is giving result as

 stdClass Object ( [follow_date] => 2012-04-17 [status] => 1 [user_id] => 8 ) stdClass Object ( [follow_date] => 2012-04-17 [status] => 2 [user_id] => 9 ) 

but when i am calling print_r($row[follow_date]);, its giving error

Fatal error: Cannot use object of type stdClass as array in /homereports/bespoke_dialing_status.php on line 34

Can somebody tell what's the problem?

3
  • the same print_r($row[follow_date]); Commented Apr 18, 2012 at 5:39
  • Hi, when I am writing echo $status = $row->status;, then it's fine but when I'm writing echo '<tr><td>' . $user_id . '</td><td>' . get_status_by_id($status) . '</td><td>' . $follow_date . '</td></tr>' ; it's giving error Catchable fatal error: Object of class stdClass could not be converted to string in /home/reports/bespoke_dialing_status.php on line 44 line 44 is } Commented Apr 18, 2012 at 5:47
  • What does print_r(get_status_by_id($status)); return? In case it is an object, select the appropriate property by using something like: get_status_by_id($status)->thePropertyYouWant Commented Apr 18, 2012 at 6:38

3 Answers 3

2

Use: $row->follow_date to access the content.

Sign up to request clarification or add additional context in comments.

Comments

1

The answer is in the error, you are trying to use stdClass as an array, which is not possible.

Since $row is a stdClass you need to use another syntax to retrieve the date.

$date = $row->follow_date;

That should give you the result you want.

Comments

0

I don't have a way to check But i remember using like $row->follow_date on a similar matter.

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.