带联接的CodeIgniter活动记录限制 - php

我的模型具有以下功能:

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。那么,如何解决呢?当limit为null时,我已经添加了if条件。

参考方案

0是一个值。这并不意味着0NULL。而NULL毫无价值。

对你来说

function getLocations($limit = 1, $offset = 0){
                               ^            ^ 
    $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();
}

limit至少设置为1,并将偏移量设置为0作为默认值。

PHP:对数组排序 - php

请如何排序以下数组Array ( 'ben' => 1.0, 'ken' => 2.0, 'sam' => 1.5 ) 至Array ( 'ken' => 2.0, 'sam' => 1.5, 'ben' =&…

PHP:将数组值加在一起 - php

我相信这比标题听起来要难一些,但我可能完全错了。我有一个像这样的数组:[["londrina",15],["cascavel",34],["londrina",23],['tiradentes',34],['tiradentes',21]] 我希望能够采用通用…

转义字符无法正常工作 - php

我试图在PHP中创建html内容,并且为onclick事件提供了一个名为uchat的div函数。该函数采用一个字符串的名称参数。如下所示:$name = "Php string"; $echostr .= "<div onClick='uchat(\'$name\')'> &l…

PHP JQuery复选框 - php

我有以下片段。 var myData = { video: $("input[name='video[]']:checked").serialize(), sinopse: $("#sinopse").val(), dia: $("#dia").val(), quem: $(&#…

PHP PDO组按列名称查询结果 - php

以下PDO查询返回以下结果:$db = new PDO('....'); $sth = $db->prepare('SELECT ...'); 结果如下: name curso ABC stack CDE stack FGH stack IJK stack LMN overflow OPQ overflow RS…