无法在查询中设置限制值

时间:2012-04-07 06:15:56

标签: php mysql codeigniter

我正在使用Codeigniter我在查询中设置“限制”的值时遇到问题,限制仅显示“limit NULL”

以下是我的代码片段。

SELECT block.loc, owner.name , block.dist_name FROM   house INNER JOIN block ON house.block_id = block.block_id INNER JOIN owner ON owner.house_id = house.house_id WHERE 
            block.dist = ? AND house.status = 5 limit ? , ? 
 $result = $this->db->query($qry, array($this->getDist(), (int) $this->getLimitStart(), (int) $this->getLimitOffset()));

转储

(int) $this->getLimitStart() is '0' and (int) $this->getLimitOffset() is '10'

3 个答案:

答案 0 :(得分:1)

据我所知,你创建了自己的getter setter对象,你在查询中提供的getter返回NULL只是因为你没有使用相同的setter。

例如:   如果您使用它($ this-> getLimitOffset()),您必须将它设置为像yourObject-> setLimitOffset(10)。我认为它现在对你有用。

答案 1 :(得分:0)

你应该像这样交换起始和偏移值

SELECT block.loc, owner.name , block.dist_name FROM   house INNER JOIN block ON house.block_id = block.block_id INNER JOIN owner ON owner.house_id = house.house_id WHERE 
        block.dist = ? AND house.status = 5 limit ? , ? 
 $result = $this->db->query($qry, array($this->getDist(), (int) $this->getLimitOffset(),(int) $this->getLimitStart()));

因为codeigniter活动记录限制第一个参数是限制abd秒是偏移。

http://codeigniter.com/user_guide/database/active_record.html

答案 2 :(得分:0)

试试这个:$this->db->limit($nrecords, $offset);

相关问题