如何在PHP中添加SQL和限制查询?

I want to show table order where status = 'confirmed', but my code doesn't work:

public function getdataorderconfirmed($limit, $offset){
    if($offset == '') {
        $sql = $this->db->query**("SELECT * FROM orderan where status = 'confirmed' LIMIT '.$limit.' 
            OFFSET 0 ");**
    return $sql->result();
    }
    else{
        **$sql = $this->db->query("SELECT * FROM orderan where status = 'confirmed' LIMIT '.$limit.' 
        OFFSET '.$offset.'");**
    return $sql->result();
    }
}

The LIMIT and OFFSET don't need their values quoted because they're numbers, so remove the single quotes around them here:

$sql = $this->db->query("SELECT * FROM orderan where status = 'confirmed'
                         LIMIT $limit OFFSET 0");

And here:

$sql = $this->db->query("SELECT * FROM orderan where status = 'confirmed'
                         LIMIT $limit OFFSET $offset");

Change the query as following, you can use PHP variables as it is if in double quotes, there is no need to concat:

public function getdataorderconfirmed($limit, $offset){
            if($offset == '') {
                $sql = $this->db->query**("SELECT * FROM orderan where status = 'confirmed' LIMIT $limit OFFSET 0");**
            return $sql->result();
            }
            else{
                **$sql = $this->db->query("SELECT * FROM orderan where status = 'confirmed' LIMIT $limit OFFSET $offset");**
            return $sql->result();
            }
        }