Advertisement
fabi0

Untitled

Nov 12th, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.40 KB | None | 0 0
  1. <?php
  2.  
  3. Class category extends CI_Model {
  4.  
  5.     function loadCategories() {
  6.         $this->db->select('c.id, c.name, count(p.cat_id) cnt');
  7.         $this->db->from('categories c');
  8.         $this->db->join('post p', 'c.id=p.cat_id', 'LEFT');
  9.         $this->db->group_by('c.name');
  10.         $this->db->order_by('cnt','DESC');
  11.         $query = $this->db->get();
  12.         return $query->result();
  13.     }
  14.  
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement