0

$get_id_siswa = check if the student available before, if not available then insert and if available then update

if(!$get_id_siswa){
$this->User_Model->insert($datax);
$user_id = $this->db->insert_id();
$datay['user_id'] = $user_id;
$datay['role_id'] = 17;
$this->load->model('User_Role_Model');
$this->User_Role_Model->insert($datay);
}else if ($get_id_asesi->nama_user == $nama_lengkap && $get_id_asesi->id_asesi == '0') {
$data_asesi_update = array('id_asesi' => $id);
$this->db->where('id', $get_id_asesi->id);
$this->db->update('t_users', $data_asesi_update);
Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
سلطان
  • 36
  • 2
  • 3
    Your question is not clear. What you want to achieve ? And where are you going wrong ? what error you are getting ? – Aman jaura Apr 29 '18 at 17:32
  • Even if your question was clear, we don't have enough information on some of the variables you are using in your conditional statements to understand what you are doing. – Alex Apr 29 '18 at 18:08
  • 1
    if not available then insert and if available then update: https://stackoverflow.com/questions/4205181/insert-into-a-mysql-table-or-update-if-exists – Vickel Apr 29 '18 at 19:03
  • `INSERT ... ON DUPLICATE KEY UPDATE ...;` – Rick James May 19 '18 at 00:08

0 Answers0