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?

Ankit Sharma
  • 3,923
  • 2
  • 29
  • 49
Thompson
  • 1,954
  • 10
  • 33
  • 58
  • the same print_r($row[follow_date]); – Thompson Apr 18 '12 at 05:39
  • Hi, when I am writing echo $status = $row->status;, then it's fine but when I'm writing echo '' . $user_id . '' . get_status_by_id($status) . '' . $follow_date . '' ; 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 **}** – Thompson Apr 18 '12 at 05: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` – stewe Apr 18 '12 at 06:38

3 Answers3

2

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

stewe
  • 41,820
  • 13
  • 79
  • 75
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.

Community
  • 1
  • 1
Kristoffer Sall-Storgaard
  • 10,576
  • 5
  • 36
  • 46
0

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

guitarlass
  • 1,587
  • 7
  • 21
  • 45