如何在CodeIgniter中创建连接查询模型


How to make Join Query model in CodeIgniter

如何在codeigniter中编写连接查询…我只想要这样的模型Select query-

public function getData($col, $table, $where = array())
{
        $this->db->select($col);
        $this->db->from($table);
        $this->db->where($where);
        $query = $this->db->get();
        $result = $query->result();
        return $result;
}

请帮助

$this->db->select('*');
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');

http://ellislab.com/codeigniter/user-guide/database/active_record.html选择在发布到stackoverflow

之前,请先阅读用户指南
join query is there..

try this

$this->db->join('second_table', 'second_table.id = first_table.id');

试试

$this->db->select('*');
$this->db->from('first_table');
$this->db->join('second_table', 'second_table.col_name = first_table.col_name');
$query=$this->db->get();
if($query->num_rows()>0){
return $query->result_array();
}

对于连接表,您可以使用join()方法。

$this->db->from(table1)
$this->db->join('table2','table1.id=table2.table1_id','join options');

on condition表示要以哪种条件连接表。连接选项是可选的。连接选项有:左、右、外、内、左、外和右外