Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] HowTo: Array/multiple words in POST that goes to a searchfunction
#1

[eluser]Devon Lambert[/eluser]
Hello CI community,

I am hoping that someone can point me in the right direction here. I have my paginated search class working properly when searching for 1 word. However, when I attempt to search for more than 1 word, it all goes to hell and it throws back an invalid/empty search.

--------------
I was actually able to solve this by doing the following in my Search Model:

MODEL:

Code:
function getSearchResults ($keyword, $limit, $offset)

    {


        if(isset($keyword)){

            if (explode(" ", $keyword) == FALSE) {
                        //Regular Search Stuff goes here...
                        }
                        
                        else {            

                $kt=split(" ",$keyword);//Breaking the string to array of words

                                

                // Now let us generate the sql

                while(list($key,$val)=each($kt)){

                    

                    if($val<>" " AND strlen($val) > 0) {

                        

                        $this->db->or_like('name', $val);

                    }

                }// end of while

                

                //$query = $this->db->query($q);

                $this->db->orderby('name', 'ASC');

                $result = $this->db->get('MY_TABLE',  $limit, $offset);

                

                $output = $result->result_array();

                return $output;

            }

        }

            
else { return 0; }
}
//...Finish off the search and count up the rows if you plan on paginating the results.

Turns out you were right on the money CJunky!

Hope it might help someone else out. :-)


Messages In This Thread
[SOLVED] HowTo: Array/multiple words in POST that goes to a searchfunction - by El Forum - 07-19-2008, 06:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB