zishan0215 / attendance

Attendance Management System for Computer Departement, JMI
Other
40 stars 128 forks source link

Admin->Teachers->Edit Teacher: Issues #16

Closed zishan0215 closed 10 years ago

zishan0215 commented 10 years ago

@nkmittal4994 Lets talk about this here

nickedes commented 10 years ago

ok get started

zishan0215 commented 10 years ago

$id = $this->teacher_m->save($array);

nickedes commented 10 years ago

actually we need to update alldetails of a table(for a row) so save runs twice .

nickedes commented 10 years ago

so i will do dis in one save statement only okay ?

zishan0215 commented 10 years ago

teacher table main you have to store id, name, username and password

zishan0215 commented 10 years ago

$array = array('teacher_name' => $this->input->post('teacher_name'), 'username' => $this->input->post('username'), 'password' => $this->teacher_m->hash($this->input->post('password')));

zishan0215 commented 10 years ago

All the information is available in the $array variable

zishan0215 commented 10 years ago

You check for validation, and then do a save.. which is absolutely fine.. But then why do a save again ?

zishan0215 commented 10 years ago

$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))

nickedes commented 10 years ago

zishan becoz some fields of d table are still not saved.. like subject_code

nickedes commented 10 years ago

okay

zishan0215 commented 10 years ago

now you store subject information in $array

zishan0215 commented 10 years ago

but when you save it in if.. the code written is: if($this->teacher_m->save($array,$this->data['teacher_id'])) {

zishan0215 commented 10 years ago

shouldn't it be if($this->subject_m->save($array,$this->data['teacher_id'])) {

nickedes commented 10 years ago

but $teacher_id is not defined it shud be save($array, $this->input->post('teacher_id'));

nickedes commented 10 years ago

yeah exactly !

zishan0215 commented 10 years ago

so that's what the problem is.. change teacher_m to subject_m in the second save

nickedes commented 10 years ago

u sure na? okay will do dat

zishan0215 commented 10 years ago

yes.. do this change and tell me what if things get working or not

zishan0215 commented 10 years ago

You can check if the update was successful by running this if($this->db->affected_rows())..

nickedes commented 10 years ago

ok

nickedes commented 10 years ago

@zishanAhmad not working

nickedes commented 10 years ago

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; }

zishan0215 commented 10 years ago

if($this->admin_m->save($array,$this->data['teacher_id'])) { why admin_m ?? you don't have to use admin_m !

nickedes commented 10 years ago

i tried wid subject_m earlier but it didnt work

zishan0215 commented 10 years ago

but there is no way you have to use admin_m

nickedes commented 10 years ago

okay saw a function using admin_m n callin save :p so used it!

zishan0215 commented 10 years ago

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

nickedes commented 10 years ago

save twice..okay

zishan0215 commented 10 years ago

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

nickedes commented 10 years ago

i didnt know about this.

zishan0215 commented 10 years ago

Ohh ! That's what model is for :P

nickedes commented 10 years ago

i will make changes n den get back to u!

zishan0215 commented 10 years ago

okay :+1:

nickedes commented 10 years ago

listen!

zishan0215 commented 10 years ago

yes ?

nickedes commented 10 years ago

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)) {

nickedes commented 10 years ago

here i dont think we need to add teacher_id in array

zishan0215 commented 10 years ago

yes.. you dont need to add teacher_id in the $array variable.. but you will be needing it in the save() method

nickedes commented 10 years ago

Yo bro :P

zishan0215 commented 10 years ago

:D

nickedes commented 10 years ago

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?

zishan0215 commented 10 years ago

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

nickedes commented 10 years ago

okay will try with that!

zishan0215 commented 10 years ago

$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

zishan0215 commented 10 years ago

then proceed to save subject inside the if part

nickedes commented 10 years ago

ok

zishan0215 commented 10 years ago

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;

}

nickedes commented 10 years ago

$id = $this->teacher_m->save($array); in dis teacher id wil not be given :octocat: ?

nickedes commented 10 years ago

okay