Sunday 15 September 2013

php - CI How to handle queries returning nothing? -



php - CI How to handle queries returning nothing? -

im building signing in form workplace users can log in , and clock hours.

i've done user goes onto timesheet , can click corresponding buttons relating each signing in , out period of dat e.g. morning break, of buttons uses updates , first button start day insert button creates record todays date, current time after each button press updates record new times relating day.

the insert button ('sign in') creates new record each time needs disabling, i'm trying model function check if record exists staff id , date, if doesn't perform normal insert new record day, if doesn't want homecoming false can check against in controller point different page instead of standard success page.

this model function : i've guessed need homecoming variable, not sure.

function clock_in($id, $time, $date) { $check -> db -> get_where('timesheet',array('datez' => $date, 'staff_id' =>$id)); if ($check -> num_rows() > 0) { $data = array('id' => null, 'staff_id' => $id, 'clock_in_time' => $time, 'clock_out_time' => null, 'break1_out' => null, 'break1_in' => null, 'lunch_out' => null, 'lunch_in' => null, 'break2_out' => null, 'break2_in' => null, 'datez' => $date); $this -> db -> insert('timesheet', $data); } else { homecoming $check; } }

this controller :

function clock_in() { $session_data = $this -> session -> userdata('logged_in'); $data['id'] = $session_data['id']; $data['time'] = date("h:i"); $data['date'] = date("y-m-d"); $this -> timesheet -> clock_in($data['id'], $data['time'], $data['date']); $this -> load -> view('timesheet/clock_in'); }

i've not attempted section yet, i'm not sure on how go checking see if variable empty load different vue , not insert anything.

all solutions , grateful, need proper way this.

do next changes:

function clock_in($id, $time, $date) { $check -> db -> get_where('timesheet',array('datez' => $date, 'staff_id' =>$id)); $data = array(); if ($check -> num_rows() > 0) { $data = array('id' => null, 'staff_id' => $id, 'clock_in_time' => $time, 'clock_out_time' => null, 'break1_out' => null, 'break1_in' => null, 'lunch_out' => null, 'lunch_in' => null, 'break2_out' => null, 'break2_in' => null, 'datez' => $date); $this -> db -> insert('timesheet', $data); } homecoming $data; // either empty or contain info }

in controller:

function clock_in() { $session_data = $this -> session -> userdata('logged_in'); $data['id'] = $session_data['id']; $data['time'] = date("h:i"); $data['date'] = date("y-m-d"); $data = $this -> timesheet -> clock_in($data['id'], $data['time'], $data['date']); if(empty($data)){ $this -> load -> view('timesheet/clock_xyz'); // view load when no info returned }else { $view['data'] = $data $this -> load -> view('timesheet/clock_in', $view); // view load when info returned } }

php mysql codeigniter

No comments:

Post a Comment