Skip to content

Instantly share code, notes, and snippets.

@dimak57
Created October 30, 2012 10:35
Show Gist options
  • Save dimak57/3979511 to your computer and use it in GitHub Desktop.
Save dimak57/3979511 to your computer and use it in GitHub Desktop.
Codeigniter. Return each category for many posts.
public function get_posts($start=0)
{
$num = $this->get_value('numnews');
if($num->numnews == FALSE){
$num->numnews = 10;
}
return $this->db->select('post.*, GROUP_CONCAT(DISTINCT category.cat_name SEPARATOR ", ") AS categories', FALSE)
->join('postcat', 'post.id = postcat.postID', 'left')
->join('category', 'postcat.catID = category.categID', 'left')
->group_by('postcat.postID')
->order_by('post.date', 'DESC')
->limit((int)$num->numnews, $start)
->get('post')->result();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment