在codeigniter中选择使用不同的列

时间:2019-03-15 10:09:54

标签: php mysql codeigniter

            This is model.php    
             function get_data_wheree($table)
    {
    $this->db->select('course_offrd_name','collg_id');
    $this->db->distinct('');

     return $this->db->get('tbl_course_offered')->result();

    }
        Here i want to use multple columns course_offrd_name and collg_id using one colums as DISTINCT keywords and second as normal select .but i m only able to select course_offrd_name and not able to print collg_id. how to print both the columns with one distinct and one normal select.
course_offrd_name as DISTINCT and collg_id as normal select 
i have made the query simple 
    how to solve the issue ..

如果需要更多代码,将对您有所帮助。 如何解决代码中的问题         预先感谢

2 个答案:

答案 0 :(得分:0)

尝试一下

function get_data_wheree($table)
   {
     $this->db->select('DISTINCT(course_offrd_name)');
     $this->db->select('collg_id');
     $this->db->where_in('course_offrd_name');//add where
     $this->db->or_where_in('collg_id');//add where
     $this->db->get('tbl_course_offered')->result();
  }

答案 1 :(得分:0)

尝试使用像这样的区别:

function get_data_wheree($table)
{
    $this->db->distinct('course_offrd_name');
    $this->db->select('collg_id');

    return $this->db->get('tbl_course_offered')->result();
}

或者您也可以使用GROUP BY

function get_data_wheree($table)
{
    $this->db->select('course_offrd_name, collg_id');
    $this->db->group_by('course_offrd_name');

    return $this->db->get('tbl_course_offered')->result();
}