Answer the question
In order to leave comments, you need to log in
`
How to form such a query to MySQL in CodeIgniter`e?
Good afternoon
Please help me.
I have articles (articles) and there are categories (politics, economics, etc.)
How can I make / create a request so that when I go to the category page: (list of my categories)
it should be displayed like this:
Politics 5 | Economics 10 (i.e. five articles in the category of politics). Here's what I want.
for example, on my site it is done
- site.com/categories/articles/politics . (articles in the "politics" category are displayed.).
PS
I hope you understand.
I'm using the CodeIgniter framework.
and please do not write me an abstraction, but specifics!
Answer the question
In order to leave comments, you need to log in
$this->db->select("category.id, category.title, COUNT(`post.id`) as posts_count")
->from('category')
->join('post','category.id = post.category_id')
->where(array('post.category_id !=' => NULL, 'category.id !=' => NULL))
->group_by(array("category.id", "category.title"))
->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question