Controller : Umpukkan 2 Variable dalam 2 Jenis Array berbeza ($data1
& $data2)
function add_account() {
$this->load->model('m_signup');
// get form variable
$first_name = $this->input->post('first_name');
$last_name = $this->input->post('last_name');
$user_email = $this->input->post('user_email');
$user_name = $this->input->post('user_name');
$user_pass = $this->input->post('user_pass');
$data1 = array($user_name, $user_email, $user_pass);
$data2 = array($first_name, $last_name);
$this->m_signup->add_account($data1, $data2);
redirect('login');
}
|
function add_account($data1, $data2) {
$this->db->trans_start();
$sql1 = "INSERT INTO users(user_name, user_email, user_pass)
VALUES (?, ?, ?)";
$this->db->query($sql1, $data1);
$id_user = $this->db->insert_id();
$sql2 = "INSERT INTO profiles(user_id, first_name, last_name)
VALUES ($id_user, ?, ?)";
$this->db->query($sql2, $data2);
$this->db->trans_complete();
return $this->db->insert_id();
}
Abd Rahman Bin Sirat
Rujukan : http://stackoverflow.com/questions/21076413/insert-array-data-into-two-table-using-codeigniter |
0 comments:
Post a Comment