codeigniter活动记录类

时间:2012-09-29 09:59:33

标签: codeigniter codeigniter-2 codeigniter-datamapper question2answer

这是我正常的mysql命令

$query = $this->db->query("SELECT `house_details`.`houses_id` , `house_details`.`house_dis` ,  `house_details`.`house_type` , `house_details`.`area` , `house_details`.`cost` , `house_details`.`user_id` , `image`.`thumb_path`
FROM (
`house_details`
)
LEFT JOIN `image` ON `image`.`house_id` = `house_details`.`houses_id`
AND `house_details`.`status` =1
GROUP BY `houses_id` DESC
LIMIT $start,$limit ");     

return $query->result();

与CI活动记录类相似的代码是什么?

2 个答案:

答案 0 :(得分:0)

试试这个,

$this->db->select('house_details.houses_id, house_details.house_dis, house_details.house_type,house_details.area,house_details.cost,house_details.user_id,image.thumb_path');      
$this->db->from('house_details');
$this->db->join('image', 'image.house_id = house_details.houses_id','left');
$this->db->where('image.status', 1);           
$this->db->order_by("house_details.houses_id DESC");    
$this->db->limit($limit, $start);

$query = $this->db->get();
return $query->result();

假设没有组,因为您想按降序排序结果集。如果group by将其更改为group_by并删除'DESC'。

答案 1 :(得分:0)

试试这个:

$this->db->select('...')->
     from('house_details')->
     join('image','image.house_id=house_details.houses_id AND image.status=1','LEFT')->
     where('...')->
     order_by('house_details.houses_id','DESC')->
     limit($start,$limit);