2

我正在使用 Codeigniter 在查询中设置“限制”的值时遇到问题,限制仅显示“限制 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'
4

3 回答 3

1

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

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

于 2012-06-23T05:39:04.537 回答
0

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

于 2012-04-07T10:07:28.680 回答
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活动记录限制的第一个参数是limit abd第二个是offset。

http://codeigniter.com/user_guide/database/active_record.html
于 2012-04-07T06:29:01.567 回答