Any body can explain Custom Queries with example...
My problem is that ..i have two table
1)campaigns
2)donations
i need the total amount of particular campaign by using the sql
query..
CODE
SELECT sum(amount) as total FROM `v1_donations` WHERE campaign_id=1
campaign Model
CODE
function getTotalAmount(){
$t = $this->query("SELECT sum(amount) as total FROM
`v1_donations` WHERE campaign_id=1");
$totalAmount = $t[0]['total'];
return $totalAmount;
}
campaign Controller
CODE
function index() {
$this->Campaign->recursive = 0;
$t = $this->Campaign->getTotalAmount();
$this->set('totolAmount',$t);
$this->set('campaigns', $this->paginate());
}
But when i go to the url i am getting the error as
Undefined index: amount [APP\models\campaign.php, line 25]
Error Context
$t = array(
array(
"v1_donations" => array()
)
)
Error Code in
$t = $this->query("SELECT amount FROM `v1_donations` WHERE
campaign_id=1");
$totalAmount = $t[0]['total']; //this line is highlighted
So please help me to solve this problem...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---