Welcome Guest, Not a member yet? Register   Sign In
Select DB Shorter?
#1

[eluser]FREEZA[/eluser]
Hey community,

here you can find me my model where i select my comments and comments count. I dont like my code because i need two functions...


Code:
function get_comments($id){

       // Get Comments
         $this->db->select('entry.id, user.uid, user.picture, user.name, comment.uid, comment.text, comment.datum, comment.e_id');
         $this->db->from('entry');
         $this->db->from('user');
         $this->db->from('comment');
         $this->db->where('user.uid = comment.uid');
         $this->db->where('entry.id = ' . $id . '');
         $this->db->where('entry.id = comment.e_id');
         $query = $this->db->get();
         $all = $query->result();
         return $all;
    }

    function count_comments($id){

       // Count Comments!

         $this->db->select('entry.id, user.uid, user.picture, user.name, comment.uid, comment.text, comment.datum, comment.e_id');
         $this->db->from('entry');
         $this->db->from('user');
         $this->db->from('comment');
         $this->db->where('user.uid = comment.uid');
         $this->db->where('entry.id = ' . $id . '');
         $this->db->where('entry.id = comment.e_id');
         $query = $this->db->get();
         $all = $query->num_rows();
         return $all;
    }


Can i write it shorter?




Theme © iAndrew 2016 - Forum software by © MyBB