You'd probably be best off creating a view (in the database, not a Cake view) to do this. Off the top of my head, the query would use a self join to grab the most recent record for each client. With proper indexing, it should be fairly efficient.
On Fri, Sep 11, 2009 at 3:42 PM, sindbad <smor...@gmail.com> wrote: > > Okay, > > thanks for your reply but from where I get the $id. This should be > Client.id but... this query selects only one row but I need to select > only one row for each client. I have 1000 clients and 21290 reports. > For every client I need to select the date of last report. > > On 11 sep., 21:52, Miles J <mileswjohn...@gmail.com> wrote: >> Well you would have to grab the last date. Heres a query, assuming you >> followed cake conventions. >> >> $result = $this->Report->find('first', array( >> 'fields' => 'Report.created', >> 'order' => 'Report.id DESC', >> 'conditions' => array('Report.client_id' => $id) >> )); >> >> Then echo it in the view: echo $result['Report']['created']; >> >> On Sep 11, 11:42 am, sindbad <smor...@gmail.com> wrote: >> >> > Hi, >> >> > first of all I want to say that I'm new to cake but with a little help >> > from book.cakephp.org and Google I've made a simple application for >> > managing clients and reports for the clients. >> > Each client has many raports. Now, in the index view of the clients I >> > need to show the date of last report. This is what I don't know how to >> > do it. >> > I'll be glad if you could tell me how to select only the date of the >> > last report for each of my clients. >> > Thanks. > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---