Re: multiple keywords in search boxes
| From: | Robert Cummings | Date: | Wed, 04 Sep 2002 20:38:10 +0000 |
| Subject: | Re: multiple keywords in search boxes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-115233@lists.php.net to get a copy of this message | ||
Jason wrote:
>
> Hi,
> What is the necessary code to return a recordset from a single text box with
> more than one keyword in it (like most search engines do)?
> Thanks
This is basic, and syntax is not checked...
if( is_array( ($words = split( '[[:space:]]+', $GET['keywordInput'] )) )
&&
count( $words ) > 0 )
{
//
// Initialize query.
//
$qString =
'SELECT xx, yy, .. FROM foo_table '
.'WHERE ';
//
// Create condition clause from word list.
//
foreach( $words as $word )
{
$qString .= "zz LIKE '%".addSlashes( $word )."% AND ";
}
//
// Trim the extraneous AND.
//
$qString = substr( $qString, whatever goes here to trim AND );
//
// Perform query.
//
}
--
.-----------------.
| Robert Cummings |
:-----------------`----------------------------.
| Webdeployer - Chief PHP and Java Programmer |
:----------------------------------------------:
| Mail : mailto:robert.cummings@webmotion.com |
| Phone : (613) 731-4046 x.109 |
:----------------------------------------------:
| Website : http://www.webmotion.com |
| Fax : (613) 260-9545 |
`----------------------------------------------'