CodeIgniter Forums
ORDER BY COUNT - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: ORDER BY COUNT (/showthread.php?tid=29982)



ORDER BY COUNT - El Forum - 04-28-2010

[eluser]aruntvla[/eluser]
Order the category according to the number of post..

Is thre any idea about how i sort a category list using the count of post..

in my case count is an integer number but how it use with an ORDER BY query..help me plz..


ORDER BY COUNT - El Forum - 04-28-2010

[eluser]pickupman[/eluser]
Have you tried:
Code:
$this->db->select('*, COUNT(category_id) as rows');
$this->db->from('posts');
$this->db->group_by('category_id');
$this->db->order_by('rows','DESC');
$query = $this->db->get();