Sounds good.
 
Will give it a try.
 
Thanks.
 
Dave

  _____  

From: Alexandru Ciobanu [mailto:[email protected]] 
Sent: September-20-09 3:43 PM
To: [email protected]
Subject: Re: Top Contributors


On 9/20/2009 7:33 PM, Dave Maharaj :: WidePixels.com wrote: 

How can this be done. 
 
Users create Posts...now I want to get a list of top 10 Posters (users who
have made the most posts). 
 
How would you do the conditions => array() for this? How can I get a list of
Users when the User.id is unknown or all of them?
 


Assuming that Post BelongsTo Users and that you have a user_id field in the
posts table, your posts model will have this method:

function top_posters($count = 10){
        return $this->find('all', array('fields' => array('Post.user_id',
'COUNT(Post.user_id) AS posts_count'),
 
'conditions' => array('Post.user_id NOT' => ''),
 
'group' => array('Post.user_id'),
 
'order' => array('posts_count DESC'),
 
'limit' => $count));
    }

This method will return an array containing user ids and posts count order
by post count, but you already figured that out.

HTH,
Alex.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to