zishan0215 / attendance

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

query queries #12

Open nickedes opened 10 years ago

nickedes commented 10 years ago

regarding teacher username check

nickedes commented 10 years ago

@zishanAhmad see dis

if($this->subject_m->check($array1)){ if($this->subject_m->insert($array)) { $this->data['confirmation'] = 1; } else { $this->data['confirmation'] = 2; } } else { $this->data['confirmation'] = 4; }

nickedes commented 10 years ago

and

$array1 = array('username' => $this->input->post('username'));

zishan0215 commented 10 years ago

waah kya naam hai !

zishan0215 commented 10 years ago

why subject_m ?

nickedes commented 10 years ago

actually der was a function already der..n it was working der :P

zishan0215 commented 10 years ago

teacher related stuff will be using teacher_m model..

zishan0215 commented 10 years ago

okay..

nickedes commented 10 years ago

and check function is

public function check($data) { $query = 'SELECT * FROM teacher where username = ' . $data['username'] ; $q = $this->db->query($query); if($q->num_rows()>0) { return FALSE; } return TRUE; }

zishan0215 commented 10 years ago

if($this->teacher_m->check($data)) { $array = array('teacher_name' => $this->input->post('teacher_name'), 'username' => $this->input->post('username'), 'password' => $this->teacher_m->hash($this->input->post('password'))); $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'), 'teacher_id' => $id); if($this->subject_m->insert($array)) { $this->data['confirmation'] = 1; } else { $this->data['confirmation'] = 2; } } else { $this->data['confirmation'] = 4;
}

use this

nickedes commented 10 years ago

okk :+1:

nickedes commented 10 years ago

just cloning d forked repo again :P

zishan0215 commented 10 years ago

check function main query main there is a problem

nickedes commented 10 years ago

query is incorrect oho!

zishan0215 commented 10 years ago

$query = 'SELECT * FROM teacher where username = ' . $data['username'] ; this will give you: SELECT * FROM teacher where username = somename

however, the name should be in quotes.. so instead, use $query = 'SELECT * FROM teacher where username = ' . "'" . $data['username'] . "'" ;

zishan0215 commented 10 years ago

the modified query will give you SELECT * FROM teacher WHERE username = 'somename'

nickedes commented 10 years ago

oh..thnx

zishan0215 commented 10 years ago

anytime :)

nickedes commented 10 years ago

but wen we write queries in mysql we dont use quotes or anything this is specifically becoz of php ?

zishan0215 commented 10 years ago

no ! we do use quotes when dealing with strings(varchar) but dont use quotes when dealing with numbers

nickedes commented 10 years ago

sunoo! here...$data should be an array na? wid username value if($this->teacher_m->check($data)) {

nickedes commented 10 years ago

i did this

$array1 = array('username' => $this->input->post('username'));
if($this->teacher_m->check_username($array1)) {.....}

zishan0215 commented 10 years ago

Working now :-) temp6

nickedes commented 10 years ago

@zishanAhmad now for edit_teacher() i will use update query for editing details ?

nickedes commented 10 years ago

$query = "UPDATE teacher SET username = 'UPDATED ITEM';

nickedes commented 10 years ago

i will do like dis only na?

zishan0215 commented 10 years ago

why dont you use the save method that is already defined in my_model ? the save method works this way:

nickedes commented 10 years ago

oki :shaved_ice:

nickedes commented 10 years ago

how to call save method?

zishan0215 commented 10 years ago

$this->teacher_m->save($data, $id)

nickedes commented 10 years ago

ok

nickedes commented 10 years ago

@zishanAhmad see dis

$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)) { $id1 = $this->teacher_m->save($array,$this->data['teacher_id']); 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->teacher_m->save($array,$this->data['teacher_id'])) { $this->data['confirmation'] = 1; } else { $this->data['confirmation'] = 2; } } else { $this->data['confirmation'] = 4;
}

nickedes commented 10 years ago

sorry by mistake close hua..

zishan0215 commented 10 years ago

looks good to me !

nickedes commented 10 years ago

ok