|
 |
|
สอบเรื่องการ INSERT และ Update คนละตารางครับ อยากทราบว่า INSERT หนึ่งตาราง และ ก็ Update อีกตาราง ครับ |
|
 |
|
|
 |
 |
|

ประมาณนี้นะครับ
ถ้าทำการ INSERT มาใหม่ id ก็ต้องไป Update อีกตารางหนึ่งด้วยนะครับ ตามภาพนะครับ
Code (PHP)
$this->upload->initialize($config);
if ($_FILES['file_name']['name']) {
$field_name = 'file_name';
if ($this->upload->do_upload('file_name')){
$gamber = $this->upload->data();
$adddata = array(
'title' => $title,
'description' => $description,
'file_name' => $gamber['file_name'],
'create_by' => $this->vendorId ,
'create_at' => date("Y-m-d H:i:s"),
// 'path' => $config['upload_path'] .'/'
);
$this->db->select_max('id');
$this->db->insert('tbl_teams',$adddata);
$insert2_teacher = $this->db->get('tbl_teams')->row_array();
$teacher_id_list = $insert2_teacher['id'];
foreach ($memberall as $key => $memberall)
{
$data2 = array
(
'id_team' => $teacher_id_list,
'id_member' => $memberall
);
$results = $this->db->insert('tbl_teams_id',$data2);
$this->db->select_max('id_team');
$this->db->where('id');
$insert2_teams = $this->db->get('tbl_teams_id')->row_array();
$teacher_id_teams = $insert2_teams['id_team'];
$data3 = array
(
// 'id' => $id,
'id_teams' => $teacher_id_teams
);
$results = $this->db->update('tbl_member',$data3);
print_r($results);
}
if($results > 0)
{
$this->session->set_flashdata('success', 'Successfully');
}
else
{
$this->session->set_flashdata('error', 'failed');
}
redirect('teams');
}
ที่ผมทำการ foreach เพราะว่า ผมทำเป็น TAG input นะครับ
ใครพอจะมีแนวการเขียนบางนะครับ
Tag : PHP, CodeIgniter

|
|
 |
 |
 |
 |
Date :
2018-10-26 12:52:21 |
By :
1711167185640399 |
View :
701 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แนะนำ แยก Model 2 ชุด ตอนวนลูปค่อยเรียกอีก Model มาทำงาน
|
 |
 |
 |
 |
Date :
2018-10-26 13:04:05 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่งมีคนถามจบไปไม่นาน....
ก่อนอ่าน ให้พึ่งระลึกไว้เสมอก่อนว่า Flow การทำงานของโปรแกรมเราเป็นแบบไหน
ถ้าแนวคิดถูก การไหลของตัวแปรถูก เรียกการทำงานอื่นๆ มาใช้ถูกตำแหน่ง มันก็สำเร็จครับ
https://www.thaicreate.com/php/forum/132415.html
จากที่ผมศึกษา codeigniter มาได้พักนึง จากการอ่าน Doc แก้ Error หรือดูข้อมูลจาก stackoverflow
ผมก็ไม่รู้ว่าเข้าใจถูกหรือผิด แต่ไม่ค่อยเห็นใคร เขียน code คิวรี่ ซ้อนใน model
อย่างที่บอกแยกฟังก์ชั่นการทำงาน แล้วเรียกฟังก์ชั่นนั้นมาใช้งาน
|
 |
 |
 |
 |
Date :
2018-10-26 14:57:10 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|