RE: [PHP] Searching
| From: | Jeff Gannaway | Date: | Mon, 17 Jul 2000 19:22:30 +0000 |
| Subject: | RE: [PHP] Searching | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-6995@lists.php.net to get a copy of this message | ||
At 01:35 PM 7/17/00 -0500, Boget, Chris wrote:
>Depending on how complex you want the search routine, it
>could be as simple as this:
>
>$searchPhrase = "this that theother";
>
>$searchWords = explode( " ", $searchPhrase );
>
>$query = "SELECT * FROM myTABLE where "
>for( $i = 0; ( $i < count( $searchWords ) - 1 ); $i++ ) {
> $query .= "search_field LIKE \"%$searchWords[$i]%\" AND ";
>
>}
>$query .= "search_field LIKE \"%$searchWords[$i]%\"
> ORDER BY record_num";
>
>or what have you...
Having done this myself, I suggest you also pad your querry with spaces like:
$query .= "search_field LIKE \"% $searchWords[$i] %\" AND ";
Otherwise you'll get results from words that only contain the search query
(someone search for MAN would get results for occurences of MANKIND, HUMAN,
MANDRAKE, SUPERMAN and such).
Later,
Jeff