2017-05-25 26 views
0

這個碼是笨寫,這是在模型文件夾 我需要在哪裏放限制和抵消?

$this->db->limit($limit,$offset); 

添加以下代碼。我在哪裏放?該模型代碼是在這裏

$this->db->where('comments.product_id', $product_id); 
     $this->db->select('comments.comment,comments.ratings,comments.comment_users_id,comment_users.name'); 
     $this->db->from('comments'); 
     $this->db->join('comment_users', 'comment_users.id = comments.comment_users_id'); 
     $this->db->join('product', 'product.product_id=comments.product_id'); 
     $this->db->order_by('comments.id', 'DESC');  
     return $this->db->get()->result(); 
+1

把它放在最後一行之前。但是我不確定訂單的重要性除了可讀性。 codeigniter從指定的不同部分構造查詢。 – inarilo

+2

我認爲在codeingniter中訂單並不重要 – JYoThI

+0

在order_by和return之間插入一行。 – Vladut

回答

0

順序是無所謂只是做這樣

$this->db->where('comments.product_id', $product_id); 
    $this->db->select('comments.comment,comments.ratings,comments.comment_users_id,comment_users.name'); 
    $this->db->from('comments'); 
    $this->db->join('comment_users', 'comment_users.id = comments.comment_users_id'); 
    $this->db->join('product', 'product.product_id=comments.product_id'); 
    $this->db->order_by('comments.id', 'DESC'); 
    $this->db->limit($limit,$offset); //here added 
    return $this->db->get()->result();