Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function do_search($query, $orderBy = 'rlsnr', $direction = 'desc', $page = 1){
- $return = array();
- $whitelist = array('rlsnr', 'rlsname', 'size');
- if(!in_array($orderBy, $whitelist)){
- $orderBy = 'rlsnr';
- }
- $whitelist = array('desc', 'asc');
- if(!in_array($direction, $whitelist)){
- $direction = 'asc';
- }
- $page = intval($page);
- if($page != 0){
- $page = $page;
- }
- else{
- $page = 1;
- }
- $where_clause = '';
- $search_query_args = array();
- $words = array();
- $words = explode(" ", $query);
- $words = array_map("trim", $words);
- $search_in = array('rlsnr', 'rlsdir', 'rlsname', 'rlsgroup');
- $i = 1;
- foreach($words as $word){
- $where_clause .= '`rlsnr` LIKE ? OR `rlsdir` LIKE ? OR `rlsname` LIKE ? OR `rlsgroup` LIKE ?';
- $search_query_args[] = '%'.$word.'%';
- $search_query_args[] = '%'.$word.'%';
- $search_query_args[] = '%'.$word.'%';
- $search_query_args[] = '%'.$word.'%';
- if($i < count($words)){
- $where_clause .= ' OR ';
- }
- $i++;
- }
- #die($where_clause);
- $options['offset'] = ($page * ENTRIES_PER_PAGE_AT_LIST - ENTRIES_PER_PAGE_AT_LIST);
- $return['number_of_pages'] = ceil(simpleDB::countRows('SELECT `rlsnr`, `rlsdir`, `rlsname`, `rlsgroup` FROM `downloads` WHERE ('.$where_clause.')', $search_query_args) / ENTRIES_PER_PAGE_AT_LIST);
- $return['entries'] = simpleDB::getRows('SELECT * FROM `downloads` WHERE ('.$where_clause.') ORDER BY '.$orderBy.' '.$direction.' LIMIT '.$options['offset'].', '.ENTRIES_PER_PAGE_AT_LIST, $search_query_args);
- return $return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement