Select, count and where using codeigniter and mysql

前端 未结 4 1184
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 07:31

I have two table as follow:

- tblSaler

    SalerID  |  SalerName | 
    ----------------------|
    1        |  sothorn   |
    ----------------------|
            


        
4条回答
  •  醉酒成梦
    2021-01-12 08:24

    Please try this code. Its working fine for me and it will help you also.

    $this->db->select('SalerName, count(*)');
    $this->db->from('tblSaler');        
    $this->db->join('tblProduct', 'tblSaler.SalerID = tblProduct.SalerID'); 
    $this->db->group_by('tblSaler.SalerID');       
    $query = $this->db->get();
    

    You can get whole SQL query using this line below

    $query = $this->db->get(); 
    echo $this->db->last_query();
    

提交回复
热议问题