Hi. The error messages indicates the undifined index of "total". Is it right?
I think you mistake the data structure which Model::query returns. If you put the statement "print_r ($t);" in the model code, you can understand the problem quickly. The structure of $t is below: Array ( [0] => Array ( [0] => Array ( [total] => 4500 ) ) ) Thus, the correct code of model is below: $totalAmount = $t[0][0]['total']; return $totalAmount; Best Wishes, Takuo Doi renju wrote: > 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 cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---