mysql,codeigniter活动记录类 [英] mysql , codeigniter active record class
本文介绍了mysql,codeigniter活动记录类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
house_id|house_name|status
1 | A | 1
2 | B | 1
3 | C | 0
4 | D | 1
5 | E | 1
6 | F | 1
table1
table1
house_id| image
2 | img1.jpg
2 | img2.jpg
1 | img3.jpg
4 | img4.jpg
1 | img5.jpg
4 | img6.jpg
3 | img7.jpg
我想从table1选择所有house_id,其中status = 1(降序)从表2,对于table1的每个house_id。
最后输出show bellow:
输出
I want select all house_id from table1 where status =1 (descending) , select distinct image from table2, for each house_id of table1 .
Finally output show bellow :
Output
house_id|house_name|image
6 | F |NULL
5 | E |NULL
4 | D |img4.jpg
2 | B |img1.jpg
1 | A |img3.jpg
请帮助我使用正常的mysql或CI活动记录类方法代码。 / h3>
please help me code with normal mysql or CI active record class method ..
推荐答案
试试这个....(正常的mysql)
try this out....(normal mysql)
SELECT t1.*,t2.image FROM table1 t1
LEFT JOIN table2 t2 on t1.house_id=t2.house_id
WHERE t1.status= 1 GROUP BY t1.house_id ORDER BY house_id desc
活动记录...
$this->db->select(t1.*,t2.image);
$this->db->from('table1'.' t1');
$this->db->join('table2'.' t2','t1.house_id=t2.house_id','left');
$this->db->where('t1.status',1);
$this->db->group_by("t1.house_id");
$this->db->order_by("house_id");
这篇关于mysql,codeigniter活动记录类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文