Note that you're fields will not be under 'UsersBook' in the array
because you're using DATE_FORMAT and COUNT. Do a debug() on the result
to see what I mean.

On Fri, Apr 24, 2009 at 2:48 PM, harpax <apsczo...@googlemail.com> wrote:
>
> Hi,
>
> The following should do the job:
>
> [..]
> // for the controller
> $params['fields'] = array(
>    'DATE_FORMAT(created, '%d.%m.%Y') AS sdate',
>    'COUNT(savedtime) AS saved',
>    'COUNT(encashedtime) AS encashed');
> $params['conditions'] = array(
>    'voucher_id' => array(8, 124, 120),
>    'created <= NOW()',
>    'DATE_SUB(NOW(), INTERVAL 30 DAY)'
> );
> $params['order'] = 'sdate';
> $params['group'] = 'sdate';
> $res = $this->UsersBook->find('all', $params);
> [..]
>
> Hope that helps,
> harpax
>
>
> On 24 Apr., 16:28, voocake <vooc...@gmail.com> wrote:
>> Hello,
>>
>> I have nice SQL query which makes most of the work for me, but i have
>> no plan how to convert it to a cakephp conform condition array. I'm
>> aware of the possibility to make a custom query, but i'm trying to
>> avoid this.
>>
>> May someone can help me with this?
>>
>> Here is the statement:
>>
>> SELECT DATE_FORMAT(created, '%d.%m.%Y') AS sdate, COUNT(savedtime) AS
>> saved , COUNT(encashedtime) AS encashed FROM users_books WHERE
>> voucher_id IN (8, 124, 120)
>> AND created <= NOW()
>> AND DATE_SUB(NOW(), INTERVAL 30 DAY)
>> GROUP BY sdate
>> ORDER BY sdate
>>
>> Thx
>> voocake
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to