mardi 21 août 2018

CodeIgniter Update database with join and if statement php

Im making a leave approval system and two leave types are there as annual and casual.

    public function approve($id, $leave_type, $leave_start, $leave_end) 
{   
    $this->db->set('status', 1);
    $this->db->where('id', $id);
    $this->db->update('leave');
    $this->db->join('users', 'users.id = leave.user_id');


    if($leave_type == "Annual")
    {
        $this->db->set('casual_left', '`casual_left`+10', FALSE);
        $this->db->where('id', $id);
        $this->db->update('users');         
    }       
    else{

        $this->db->set('annual_left', '`annual_left`+3', FALSE);
        $this->db->where('id', $id);
        $this->db->update('users');
    }

    return $this->db->affected_rows() > 0;     
}

Im not sure about the sequence of the conditions.

Aucun commentaire:

Enregistrer un commentaire