0

I have this query statement in SQL. I am using CodeIgniter and I would like to create these statements inline in PHP code.

UPDATE `dbhpl`.`pelayanan` 
    SET `pelayanan`.`ID_STATUS` = CASE 
    WHEN `pelayanan`.`LAMA` > `pelayanan`.`ESTIMASI` THEN '1' 
    WHEN `pelayanan`.`LAMA` <= `pelayanan`.`ESTIMASI` THEN '2' 
END  

How is the code for controller.php and model.php?

1 Answer 1

3

Model Function :

public function update_special() {
        $str = "UPDATE dbhpl.pelayanan SET "
                . "pelayanan.ID_STATUS = "
                . "CASE WHEN pelayanan.LAMA > pelayanan.ESTIMASI THEN '1'"
                . " WHEN pelayanan.LAMA <= pelayanan.ESTIMASI "
                . "THEN '2' END";
        $this->db->query($str);
        if ($this->db->affected_rows() > 0) {
            return true;
        } else {
            return false;
        }
    }

Controller Function

 function controller_function(){
        return $this->model->update_special();
    }
Sign up to request clarification or add additional context in comments.

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.