Welcome Guest, Not a member yet? Register   Sign In
How i can select most common value with codeigniter
#1

Hi guys,
I have a question. I wanted to know how to select the most common value in a table while doing a join. For example: I have a "blog" table and another table "comments_blog" and I want to select from the "comments" the ID of the post table that most repeats.
The table would have this content:

// id - id_post - content
1 2 test
2 2 test2
3 2 test3
4 3 test4
4 5 test5

I looked in the official guide of codeigniter but found nothing. and truth i never done this type of query. I Try doing this:

Code:
$this->db->join( 'comments_blog', 'comments_blog' . '.' . 'id_blog' . ' = ' . 'blog' . '.' . 'id' );
$query = $this->db->query('SELECT id_blog AS magnitude FROM comments_blog GROUP BY id_blog ORDER BY magnitude DESC LIMIT 3');

I want to do this to know which is the most popular post. Not get me wrong, I do not want to you do the work for me, i just want to explain to me how you could do
Reply


Messages In This Thread
How i can select most common value with codeigniter - by Smith - 11-30-2014, 09:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB