(1-1/1)
Hi Steve,
Today I had similar problems and I found this thread via google. I try this and it's work:
$attributes = $totalhead->attributes();
print_r($attributes['total']);
I hope this could help others that found this thread via google.
(1-1/1)
Subject: Help trying to pull data from object when using a SUM as query.
Hello - I have the following query which works and gets the correct data:
$totalhead = Lot::find_by_sql("SELECT SUM as total FROM lots WHERE buyer_id = '{$lot->buyer_id}'");
Running print_r($totalhead) yields the following:
Array ( [0] => Lot Object ( [errors] => [attributes:ActiveRecord\Model:private] => Array ( [total] => 300 ) [__dirty:ActiveRecord\Model:private] => [__readonly:ActiveRecord\Model:private] => 1 [__relationships:ActiveRecord\Model:private] => Array ( ) [__new_record:ActiveRecord\Model:private] => ) )
The data I need is shown in the [total] => 300 part (I need to print the 300)
I thought doing $totalhead->total would print the 300 part but instead it prints blank.
Probably a rookie mistake and very simple for someone with more experience to tell me where I'm going wrong!
Thanks a lot guys!