php - if query is not update -


i know best way make query's if statement. because use 1 function codeigniter edit main function,

so combines both query's , makes if query not update insert way best way

public function addusergroup($data) {     $this->db->query("insert " . $this->db->dbprefix . "user_group set      name = " . $this->db->escape($data['name']) . ",      permission = " . (isset($data['permission']) ? $this->db->escape(serialize($data['permission'])) : '') . " "); }  public function editusergroup($user_group_id, $data) {     $this->db->query("update " . $this->db->dbprefix . "user_group set      name = " . $this->db->escape($data['name']) . ",      permission = " . (isset($data['permission']) ? $this->db->escape(serialize($data['permission'])) : '') . " user_group_id = '" . (int)$user_group_id . "'"); } 

you can set if/else condition using "user_group_id". think must coming post array $this->input->post('user_group_id').

so can create 1 function check these conditions below:

function my_function(){    if($this->input->post('user_group_id')){     // call update query    }else{     // call insert query    } } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -