Your column prefixes are used by the record parser to build the result
set array.
If you changed it as follows (formatting added for clarity only):
SELECT i.id,
i.client_id,
ifnull(total,'0') as i.total_due,
ifnull(i.due,'NA') as i.due_date,
ifnull(sum(p.amount),0) as i.total_paid,
ifnull(i.total - sum(p.amount),i.total) as i.total_still_due
FROM invoices LEFT JOIN payments ON p.invoice_id = i.id
WHERE i.total > 0
GROUP BY p.client_id
ORDER BY due_date";
Then, everything gets put in the [i] array. You could change [i] above
to give it more meaning.
Was this what you needed?
Fred
hutchic wrote:
> With the following function
>
> function calculate_due(){
> $query = "
> SELECT i.id, i.client_id, ifnull(total,'0') as
> total_due,
> ifnull(i.due,'NA') as due_date, ifnull(sum(p.amount),0) as total_paid,
> ifnull(i.total - sum(p.amount),i.total) as total_still_due
> FROM invoices i LEFT JOIN payments p ON p.invoice_id =
> i.id
> WHERE total > 0
> GROUP BY p.client_id
> ORDER BY due_date";
> $ret = $this->query($query);
> pr($ret);
> die('');
> }
>
> The output I get is
>
> Array
> (
> [0] => Array
> (
> [i] => Array
> (
> [id] => 8
> [client_id] => 1
> )
>
> [0] => Array
> (
> [total_due] => 3.250
> [due_date] => NA
> [total_paid] => 0.00
> [total_still_due] => 3.250
> )
>
> )
>
> )
>
> In version 1.1.19.6305
>
> Help is greatly appreciated
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---