That kicks up a 500 server error ........

I tried this:

$this->Photo->find('all',
                        array(
                'fields'        => array('filename', 'user_id',
'contest_id', 'MAX(revision_id)'),
                                'conditions'    => array('contest_id' => 
$this->Contest['Contest']
['id']),
                "conditions"    => "WHERE contest_id = " . $this-
>Contest['Contest']['id'] . " GROUP BY user_id",
                                'order'                 => 'modified DESC',
                'limit'         => 12
                                )
                        )

Also gave me a 500 error..


On Apr 19, 10:03 am, "b logica" <[EMAIL PROTECTED]> wrote:
> Try something like this:
>
> $criteria = array(
>         'fields' => array(
>                 'TABLE_ALIAS.user_id', 'MAX(TABLE_ALIAS.revision_id)'
>         ),
>         'conditions' => array(
>                 '1=1 GROUP BY TABLE_ALIAS.user_id'
>         ),
>         'limit' => 15
> );
>
> On Sat, Apr 19, 2008 at 10:23 AM, John R <[EMAIL PROTECTED]> wrote:
>
> >  You are correct - this would not work because if there were less than
> >  15 unique revisions, it would grab dupes per use.
>
> >  The MAX() option you showed works perfectly - except when you do a
> >  $this->Model->query(sql), it doesn't grab the recursive results, which
> >  I really need.
>
> >  On Apr 18, 8:41 pm, "b logica" <[EMAIL PROTECTED]> wrote:
> >  > No need for a timestamp if the revision_id is a SERIAL (or
> >  > AUTO_INCREMENT or whatever).
>
> >  > I think you're thinking of something more along the lines of:
>
> >  > SELECT user_id, revision_id FROM the_table ORDER BY revision_id,
> >  > user_id DESC LIMIT 15;
>
> >  > Including the user_id in ORDER BY clause allows for overlap in the 
> > revision_id.
>
> >  > But John wants the latest revision--and only the latest--per user.
> >  > IOW, he doesn't want more than one revision_id for each user.
>
> > > On Fri, Apr 18, 2008 at 6:32 PM, Robert <[EMAIL PROTECTED]> wrote:
>
> >  > >  I would add a time field to the database record for each revision.
> >  > >  Then order by descending time and limit your query to 15 rows.  (You
> >  > >  can order by descending revision_id also, but once you have many users
> >  > >  you could easily have more than 15 records where the greatest
> >  > >  revision_id's are equal, and they won't be useful for showing only the
> >  > >  most recent revisions.)
>
> >  > >  On Apr 18, 4:10 pm, John R <[EMAIL PROTECTED]> wrote:
> >  > >  > In this app, users can upload photos, and then revise them.
>
> >  > >  > The app stores a log of all revisions so they can easily go back to
> >  > >  > them.
>
> >  > >  > The database has: user_id and revision_id
>
> >  > >  > I am trying to write a statement that grabs only the 15 latest
> >  > >  > (highest #) revisions for all users.
>
> >  > >  > So .. if the table looks like:
>
> >  > >  > user_id       revision_id
> >  > >  > 1                1
> >  > >  > 1                2
> >  > >  > 2                1
> >  > >  > 3                 1
> >  > >  > 1                3
> >  > >  > 1                4
> >  > >  > 3                2
>
> >  > >  > It would grab three records: user 1 revision 4, user 2 revision 1 
> > and
> >  > >  > user 3 revision 2
>
> >  > >  > Any help?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to