I have one Skill from which in user can add more skill of them.
Here is my table of student_skill
:
+------+--------------+--------------------------------------+
| id | student_id | skill |
+------+--------------+--------------------------------------+
| 1 | 1 | 10 |
| 2 | 1 | 3 |
| 3 | 2 | 2 |
| 4 | 2 | 6 |
+------+--------------+--------------------------------------+
My Html Form:
<form action="<?= base_url('skill/add_new_skill') ?>" method="post">
Select Skills:
<select name="skill[]" id="skill" multiple>
<option value="1">Physics</option>
<option value="2">Accounting </option>
<option value="3">Business Activity Monitoring</option>
<option value="4">Redhat Linux </option>
// More Skill Options Here
</select>
<input type="submit" name="submit">
</form>
The Problem:
I don't get that how do I Insert and Update that multiple rows.
I want to use insert_batch
& update_batch
to add & update skills.
What I have Done So far?
Here is my controller code:
//Controller Functions
public function insert_skill(){
$this->load->model ('skill_model');
$skill_data = $this->input->post();
$update_status = $this->skill_model->insert_student_skill($skill_data);
}
public function update_skills(){
$this->load->model ('skill_model');
$skill_data = $this->input->post();
$update_status = $this->skill_model->update_student_skills($skill_data);
}
//Model Functions
//Update Skill Model
public function update_student_skills($skill_data){
//What should i do to update student data
$this->db->update_batch('student_skill', $skill_data);
}
//Insert Skill Model
public function insert_student_skill($skill_data){
//What should i do to Insert student data
$this->db->insert_batch('student_skill', $skill_data);
}
Problem Case Scenario 1: If User Select
'Physics','Accounting'
First and In updating process if the user changes the selected options according to'Physics','Redhat Linux'
How Do I Update Skill in this type of scenario?