【发布时间】:2015-11-02 00:20:38
【问题描述】:
我的模型中有以下功能:
function getLocations($limit = null, $offset = null){
$this->db->select('*');
$this->db->from('location');
$this->db->join('process', 'process.process_id=location.process_id');
$this->db->join('line', 'line.line_id=process.line_id');
$this->db->limit($limit, $offset);
$this->db->order_by('location_id', 'asc');
return $this->db->get()->result();
}
然后使用:$this->the_model->getLocations() 执行,产生以下查询:
SELECT *
FROM "location"
JOIN "process" ON "process"."process_id"="location"."process_id"
JOIN "line" ON "line"."line_id"="process"."line_id"
ORDER BY "location_id" asc LIMIT 0
注意LIMIT 0,当我执行$this->db->order_by('item_id', 'asc')->get('item', $limit, $offset)->result() 时不会发生这种情况。没有LIMIT 0 甚至限制,偏移量是null。那么,如何解决这个问题呢?当限制为空时,我已经添加了if 条件。
【问题讨论】:
-
你好,null不代表=0,你可以试试getLocations($limit = 0,$offset = 0)
标签: php sql codeigniter