php - where() not working in codeigniter database -


i wrote code search in table search string in posts show = 1. when run code where('show',1) not affected , rows having show = 0 returned database, problem?

    public function json_search($str)     {         $out['threadt'] = $this->db         ->select('id')         ->from('posts')         ->like('title',$str)         ->or_like('story',$str)         ->or_like('description',$str)         ->or_like('full-story',$str)         ->where('date <',time())         ->where('show',1)         ->get()     ->result_array();      } 

you should try this, should work:

function json_search($str) {     $where  = "( story '%".$str."%' or title '%".$str."%' or description '%".$str."%' or full-story '%".$str."%' )";     $out['threadt'] = $this->db     ->select('id')     ->from('posts')     /*->like('title',$str)     ->or_like('story',$str)     ->or_like('description',$str)     ->or_like('full-story',$str)*/     ->where( $where, false, false )     ->where('date <',time())     ->where('show',1)     ->get()     ->result_array();  } 

see commented part above, when you're using this, appending or clauses , interferes show clause.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -