{Solved} Combine 2 results into one. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: {Solved} Combine 2 results into one. (/showthread.php?tid=66259) |
{Solved} Combine 2 results into one. - wolfgang1983 - 09-28-2016 I have these two model functions. The get_posts function effects the function total_posts_by_user PHP Code: public function get_posts() { PHP Code: public function total_posts_by_user($user_id, $reply_id, $post_id) { On my controller function I have used $this->db->last_query() for the total_posts_by_user($user_id, $reply_id, $post_id) And out puts like code below but MY Question: On the get_posts In stead of making the 2 admin show how could I combine the 2 in to one using something like group_by and then changing the total_post to 2. I have tried group by not to sure what missing. $this->db->group_by('p.reply_id'); and $this->db->group_by('p.user_id'); Code: SELECT * FROM `post` WHERE `post_id` = '1' AND `reply_id` = '0' AND `user_id` = '2' // Main post Image Controller PHP Code: <?php RE: Combine 2 results into one. - salain - 09-29-2016 Hi, You need to count the user_id with your group by PHP Code: public function get_posts() { RE: Combine 2 results into one. - wolfgang1983 - 09-29-2016 (09-29-2016, 12:35 AM)salain Wrote: Hi, I think that did the trick but will test it some more. |