2

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();
    }
}
1
  • 3
    Because you're mixing single and double quotes. Commented May 17, 2018 at 6:19

2 Answers 2

2

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");
Sign up to request clarification or add additional context in comments.

Comments

1

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();
            }
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.