Welcome Guest, Not a member yet? Register   Sign In
Help with generating db driven dropdown search function
#4

[eluser]pickupman[/eluser]
You would want to chain ->like() if each of the criteria is required for a result.
Code:
$searchflds = array('Publications_Title','Date','Type','First_Name','Last_Name');    
                $this->db->select('Publication_ID,Main_Author, Other_SEI_Authors,Other_non_SEI_Authors,Publications_Title,Publications_Photo,Type,Date,First_Name,Last_Name');
                $this->db->from('tbl_publications');
                $this->db->join('tbl_staff','StaffID = Main_Author');
                
                foreach ($search_str as $ss)
                {  
                    foreach ($searchflds as $fld){
                        $this->db->like($fld, $ss);                        
                    }
                }
                $this->db->orderby('Date','desc');
                $query=$this->db->get();

If you want any match, use (you can chain or_like(). CI will add the OR when it needs it):
Code:
$searchflds = array('Publications_Title','Date','Type','First_Name','Last_Name');    
                $this->db->select('Publication_ID,Main_Author, Other_SEI_Authors,Other_non_SEI_Authors,Publications_Title,Publications_Photo,Type,Date,First_Name,Last_Name');
                $this->db->from('tbl_publications');
                $this->db->join('tbl_staff','StaffID = Main_Author');
                
                foreach ($search_str as $ss)
                {  
                    foreach ($searchflds as $fld){
                        $this->db->or_like($fld, $ss);
                    }
                }
                $this->db->orderby('Date','desc');
                $query=$this->db->get();

You want to consider creating a sub statement like:
Code:
$where ="WHERE (Publication_Title LIKE '%".$ss."%' OR Publication_Title LIKE '%".$ss."%') AND (Type LIKE '%".$ss."%' OR Type LIKE '%".$ss."%') AND (//next)";
$this->db->where($where);

Depend on your desired results, try each see what you get and check which way is faster.


Messages In This Thread
Help with generating db driven dropdown search function - by El Forum - 04-19-2010, 03:43 PM
Help with generating db driven dropdown search function - by El Forum - 04-19-2010, 09:54 PM
Help with generating db driven dropdown search function - by El Forum - 04-20-2010, 10:38 AM
Help with generating db driven dropdown search function - by El Forum - 04-20-2010, 12:14 PM
Help with generating db driven dropdown search function - by El Forum - 04-28-2010, 09:56 AM
Help with generating db driven dropdown search function - by El Forum - 04-28-2010, 07:18 PM
Help with generating db driven dropdown search function - by El Forum - 05-08-2010, 12:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB