Welcome Guest, Not a member yet? Register   Sign In
Query returning only first row
#1

[eluser]ibnclaudius[/eluser]
I've this query, but I don't know it's returning only the first row..

Code:
return $this->db->select('a.id AS topic_id,
                          a.text AS topic_text,
                          a.date AS topic_date,
                          b.name AS author_name,
                          b.picture AS author_picture,
                          b.facebook_id AS author_facebook_id,
                          SUM(CASE WHEN c.topic_id IS NOT NULL THEN 1 ELSE 0 END) AS topic_likes_number,
                          SUM(CASE WHEN c.topic_id IS NOT NULL AND c.author_id = ' . $user_id . ' THEN 1 ELSE 0 END) AS topic_liked,
                          SUM(CASE WHEN d.topic_id IS NOT NULL THEN 1 ELSE 0 END) AS topic_dislikes_number,
                          SUM(CASE WHEN d.topic_id IS NOT NULL AND c.author_id = ' . $user_id . ' THEN 1 ELSE 0 END) AS topic_disliked,
                          SUM(CASE WHEN e.topic_id IS NOT NULL THEN 1 ELSE 0 END) AS topic_comments_number')
                ->from('topics AS a')
                ->join('users AS b', 'b.id = a.author_id', 'INNER')
                ->join('topics_likes AS c', 'c.topic_id = a.id', 'LEFT')
                ->join('topics_dislikes AS d', 'c.topic_id = a.id', 'LEFT')
                ->join('comments AS e', 'e.topic_id = a.id', 'LEFT')
                ->get()
                ->result_array();
#2

[eluser]DarkManX[/eluser]
Try to just use pure mysql-code in the db. there have to be the mistake.
#3

[eluser]InsiteFX[/eluser]
After you run your query do this:
Code:
echo $this->db->last_query();

And see what is going on.

CodeIgniter Users Guide - Queries




Theme © iAndrew 2016 - Forum software by © MyBB