escape(trim($_GET['search'])); } else { $search = ""; } if(isset($_GET['offset'])){ $offset = $db -> escape(trim($_GET['offset'])); } else { $offset = ""; } if(isset($_GET['limit'])){ $limit = $db -> escape(trim($_GET['limit'])); $offset_limit = " LIMIT ". $offset.",".$limit; } else { $offset_limit = ""; } $json_arr['rows'] = array(); $count = " count(ep.id) "; $fields = " ep.id, ep.position_name, e.first_name, e.last_name, ep.status "; $position_query = "SELECT %s FROM `employee_position` ep INNER JOIN `employee` e ON ep.add_by=e.id WHERE ep.position_name LIKE '%%%s%%' AND ep.id != 0 ORDER BY position_name ASC "; $position_list_query = $db -> sql_query(sprintf($position_query, $fields, $search)." $offset_limit"); $position_list_query_count = $db -> select(sprintf($position_query,$count,$search)); while($row = $position_list_query->fetch_assoc()) { $json_arr['rows'] = array_merge($json_arr['rows'],array(array('id'=>$row['id'], 'name'=>$row['position_name'], 'add_by'=>$row['first_name']. " " .$row['last_name'], 'status'=>$row['status']//, //'customer_name_id'=>(($row['name']) <> "" ? $row['name'] : "(Not provided)") // 'customer_name_id'=>(($row['customer_id']) <> "" ? $row['customer_id'] : "") . " / " . // (($row['name']) <> "" ? $row['name'] : "(Not provided)") ))); } $json_arr['total'] = $position_list_query_count; //total number of result echo json_encode($json_arr); ?>