-1

this is my normal mysql command

$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();

what is the similar code with CI active record class ??

4

2 回答 2

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 存在,则将其更改为 group_by 并删除“DESC”。

于 2012-09-29T10:12:36.427 回答
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);
于 2012-09-29T16:20:04.767 回答