Re: Top Contributors
You should also have a look at CounterCache: http://book.cakephp.org/view/816/counterCache-Cache-your-count Hope that helps. Markus --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
RE: Top Contributors
Sounds good. Will give it a try. Thanks. Dave _ From: Alexandru Ciobanu [mailto:ics.cake...@gmail.com] Sent: September-20-09 3:43 PM To: cake-php@googlegroups.com 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 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 -~--~~~~--~~--~--~---
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 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 -~--~~~~--~~--~--~---