Closed zishan0215 closed 10 years ago
ok get started
$id = $this->teacher_m->save($array);
actually we need to update alldetails of a table(for a row) so save runs twice .
so i will do dis in one save statement only okay ?
teacher table main you have to store id, name, username and password
$array = array('teacher_name' => $this->input->post('teacher_name'), 'username' => $this->input->post('username'), 'password' => $this->teacher_m->hash($this->input->post('password')));
All the information is available in the $array variable
You check for validation, and then do a save.. which is absolutely fine.. But then why do a save again ?
$array = array('subject_code' => $this->input->post('subject_code'), 'subject_name' => $this->input->post('subject_name'), 'semester' => $this->input->post('semester'), 'teacher_id' => $id);
if($this->subject_m->insert($array))
zishan becoz some fields of d table are still not saved.. like subject_code
okay
now you store subject information in $array
but when you save it in if.. the code written is: if($this->teacher_m->save($array,$this->data['teacher_id'])) {
shouldn't it be if($this->subject_m->save($array,$this->data['teacher_id'])) {
but $teacher_id is not defined it shud be save($array, $this->input->post('teacher_id'));
yeah exactly !
so that's what the problem is.. change teacher_m to subject_m in the second save
u sure na? okay will do dat
yes.. do this change and tell me what if things get working or not
You can check if the update was successful by running this if($this->db->affected_rows())..
ok
@zishanAhmad not working
if ($this->form_validation->run() == TRUE) {
$array = array('teacher_name' => $this->input->post('teacher_name'), 'username' => $this->input->post('username'), 'password' => $this->teacher_m->hash($this->input->post('password')), 'subject_code' => $this->input->post('subject_code'), 'subject_name' => $this->input->post('subject_name'), 'semester' => $this->input->post('semester'));
if($this->teacher_m->check_username($array)) {
if($this->admin_m->save($array,$this->data['teacher_id'])) {
$this->data['confirmation'] = 1;
} else {
$this->data['confirmation'] = 2;
}
} else {
$this->data['confirmation'] = 4;
}
} else {
$this->data['confirmation'] = 3;
}
if($this->admin_m->save($array,$this->data['teacher_id'])) { why admin_m ?? you don't have to use admin_m !
i tried wid subject_m earlier but it didnt work
but there is no way you have to use admin_m
okay saw a function using admin_m n callin save :p so used it!
admin_m means you are using the admin table.. which is not what you're doing.. you have to use save twice.. like before. first using teacher and then using subject
save twice..okay
which model you choose depends on which table you want to work with,,, admin_m : admin table student_m: student table teacher_m: teacher_table
i didnt know about this.
Ohh ! That's what model is for :P
i will make changes n den get back to u!
okay :+1:
listen!
yes ?
before saving second time saving unset($array); $array = array('subject_code' => $this->input->post('subject_code'), 'subject_name' => $this->input->post('subject_name'), 'semester' => $this->input->post('semester'), 'teacher_id' => $id); if($this->subject_m->insert($array)) {
here i dont think we need to add teacher_id in array
yes.. you dont need to add teacher_id in the $array variable.. but you will be needing it in the save() method
Yo bro :P
:D
if ($this->form_validation->run() == TRUE) {
$array = array('teacher_name' => $this->input->post('teacher_name'), 'username' => $this->input->post('username'), 'password' => $this->teacher_m->hash($this->input->post('password')));
if($this->teacher_m->check_username($array)) {
$id = $this->teacher_m->save($array);
unset($array);
$array = array('subject_code' => $this->input->post('subject_code'), 'subject_name' => $this->input->post('subject_name'), 'semester' => $this->input->post('semester'));
if($this->subject_m->save($array,$this->data['teacher_id'])) {
$this->data['confirmation'] = 1;
} else {
$this->data['confirmation'] = 2;
}
} else {
$this->data['confirmation'] = 4;
}
}
now?
If the save method for subject doesn't work.. its probably because teacher_id is being passed as the parameter which means that the save method will assume it to be the primary key.. which it is not.. So if that's the case, then write your own query in subject_m and use that to update the changes
okay will try with that!
$id = $this->teacher_m->save($array); After you save the changes to teacher.. use an if else statement to check whether the changes were successful or not
then proceed to save subject inside the if part
ok
so it becomes something like this if($this->teacher_m->check_username($array)) { $id = $this->teacher_m->save($array); if($this->db->affected_rows()) { unset($array); $array = array('subject_code' => $this->input->post('subject_code'), 'subject_name' => $this->input->post('subject_name'), 'semester' => $this->input->post('semester')); if($this->subject_m->save($array,$this->data['teacher_id'])) { $this->data['confirmation'] = 1; } else { $this->data['confirmation'] = 2; }
} else { error updating changes to teacher } } else { $this->data['confirmation'] = 4;
}
$id = $this->teacher_m->save($array); in dis teacher id wil not be given :octocat: ?
okay
@nkmittal4994 Lets talk about this here