Re: Multiple work mySql database search.

From: Date: Wed, 21 Apr 2004 13:46:46 +0000
Subject: Re: Multiple work mySql database search.
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-34000@lists.php.net to get a copy of this message
Martin E. Koss wrote:
I have a product database which can be searched for a keyword in up to 3 fields; using this select query: $sql_select = "SELECT * from productlist WHERE (Name LIKE '%$SearchText%') OR (Description LIKE '%$SearchText%') OR (Keywords LIKE '%$SearchText%') ORDER BY Name"; What I really want to achieve is if someone enters more than one work in the search for, how can I get the select query to search for one, the other, or both? WHERE (field LIKE '%word1%' OR field LIKE '%word2%' [etc etc])
I've thought of putting an option on the search for the user to select 'All Words' or 'Any Word' so that the select query could deal with the search based on the full phrase they entered or any of the words. My problem is how to build the query. Join them either with ANDs or ORs like this:
Searching for all words in a field: WHERE (field LIKE '%something% AND field LIKE '%other_thing') Searching for any of the words in a field: [read above in the previous question] Bruno Ferreira --- [This E-mail scanned for viruses by Declude Virus]

« previous php.db (#34000) next »