从两个表左边加入codeigniter,想要显示两个值

时间:2017-04-20 04:30:32

标签: php sql codeigniter

表1包含时间表,表2包含类别名称。我需要使用左连接从两个表中显示带有id的类别名称和时间,怎么可能?

2 个答案:

答案 0 :(得分:1)

尝试以下查询

select * from table1 left join table2 on table1.id=table2.id
CI中的

$this->db->select('*');
$this->db->from('table1');
$this->db->join('table2 ', 'table1.id=table2.id', 'left');
$query = $this->db->get();

答案 1 :(得分:0)

Use this code which will help to get the data from the two tables and getting the two values from both the tables:
<?PHP
 $this->db->select('t1.name, t2.desc')
 ->from('table_first as t1')
 ->where('t1.id', $id)
 ->join('table_second as t2', 't1.id = t2.id', 'LEFT')
 ->get();
?>