Re: Multiple word queries

From: Date: Thu, 01 Jul 2004 03:22:04 +0000
Subject: Re: Multiple word queries
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-35073@lists.php.net to get a copy of this message
Shiloh Madsen wrote:
say someone enters a search string of "cat dog mouse rabbit" (without the qoutes) into my search box. What I need for the results page to do is to construct a query that will search through my keywords table for every instance of ANY of those words. How would you suggest I handle this?
For that simple example, you can just explode the string on the space and create a WHERE clause entry for each word. For example: $words = explode(' ',$_GET['search_text']); foreach($words as $word) { $query .= " AND column LIKE '%$word%' "; } Gets more complicated the more you want to parse the search text and is dependant upon what database you're using. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.db (#35073) next »