Tuesday, August 31, 2010

Re: Get Most Viewed Question

In controller
$this->set('most_viewed', $this->Post->find('all', array('limit' => 10, 'order' => array('Post.views' => 'DESC')));

In view
$most_view - your top 10

And don't forget add index to "posts.views" column in db

2010/9/1 Dave Maharaj <me@davemaharaj.com>

I am stumped on how to get top 10 Posts based on the "views" count in the database?

Every time a Post is viewed I auto add 1 to the view count. But to get the top 10?

Any ideas how to do this?

 

Thanks

 

Dave

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
 
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
 
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: