public function getResult($query) { $records = $this->db->query($query); return Result_data::instantiate($records); }
public function search() { $term = $this->input->post('term'); $arr = explode(' ', $term); $final = new Result_data(); $subQuery = ""; $i = 1; $j = count($arr); foreach ($arr as $a) { $subQuery = $subQuery . "first_name like '" . $a . "%' or last_name like '" . $a . "%'"; if ($i++ == $j) { break; } $subQuery = $subQuery . " or "; } $user = $this->session->userdata('user_id'); //$query = "select user_id,user_email,user_name,password,join_time,verify_condition,status,first_name,last_name,mobile_number,gender,profile_pic,security_question,security_answer,verify_code, 'true' as friendship from (select * from user_info where ".$subQuery.")t1 natural join (select friend_id as user_id from friend_info where user_id=".$user." and friend_id<>".$user.")t2 union distinct select user_id,user_email,user_name,password,join_time,verify_condition,status,first_name,last_name,mobile_number,gender,profile_pic,security_question,security_answer,verify_code, 'false' as friendship from (select * from user_info where ".$subQuery.")t1 where user_id not in(select friend_id as user_id from friend_info where user_id=".$user." and friend_id<>".$user.") and user_id<>".$user.""; $query = "select user_id,user_email,user_name,password,join_time,verify_condition,status,first_name,last_name,mobile_number,gender,profile_pic,security_question,security_answer,verify_code, 'true' as friendship from (select * from user_info where " . $subQuery . ")t1 natural join (select friend_id as user_id from friend_info where user_id=" . $user . " and friend_id<>" . $user . " and friend_status='confirmed')t2 union distinct select user_id,user_email,user_name,password,join_time,verify_condition,status,first_name,last_name,mobile_number,gender,profile_pic,security_question,security_answer,verify_code, 'pending' as friendship from (select * from user_info where " . $subQuery . ")t1 natural join (select friend_id as user_id from friend_info where user_id=" . $user . " and friend_id<>" . $user . " and friend_status='pending')t2 union distinct select user_id,user_email,user_name,password,join_time,verify_condition,status,first_name,last_name,mobile_number,gender,profile_pic,security_question,security_answer,verify_code, 'false' as friendship from (select * from user_info where " . $subQuery . ")t1 where user_id not in(select friend_id as user_id from friend_info where user_id=" . $user . " and friend_id<>" . $user . ") and user_id<>" . $user . ""; //echo $query;die; $data['object'] = Result_data::getResult($query); $this->load->view('user/header'); $this->load->view('user/ajax'); $this->load->view('user/sidebar_left'); $this->load->view('user/navbar_top'); $this->load->view('user/results', $data); $this->load->view('user/footer'); }