--- Jer <[EMAIL PROTECTED]> wrote:
> 
> Currently, I use LIKE in the query (i.e. WHERE title LIKE '$search').
> I'm finding that that is too restrictive.
> 
> For example, if someone were to search for the title "Me, Myself &
> Irene", they would actually need to search for "me, myself & irene".
> If they search for "me myself irene" or "me irene" or "me, myself and
> irene", the search would come back with nothing.
> 
> Is there a better way to search than using LIKE in the query?


Here is a sample program following the model I use in my PHP & MySQL classes.

$ignore = array("and", "&");
$input  = "Me, Myself & Irene";
$words  = split("[, .]", $input);
$query  = "SELECT * FROM tablename WHERE 1=1 ";
foreach($words as $w)
{
 if (! in_array($w, $ignore))
 {
  $query .= "AND (fieldname1 LIKE '%$w% OR fieldname2 LIKE '%$w%') ";
 }
}

print $query; // process in the usual way
_____
James


James D. Keeline
http://www.Keeline.com  http://www.Keeline.com/articles
http://Stratemeyer.org  http://www.Keeline.com/TSCollection

http://www.ITeachPHP.com -- Free Computer Classes: Linux, PHP, etc.
Spring Semester Begins Jan 31 -- New Classes Start Every Few Weeks.


Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to