Thread: search funtion
View Single Post
Old 02-15-2005, 06:25 PM   #3 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Split the input name into two vars (or an array) and do something similar to tekno's SQL statement. Although depending on the requirements, you might want to use the "LIKE" statement to perform partial matches.

For a loose search I typically do something like:

eg:
PHP Code:
$k 'SMITH, MIKE';
$k preg_replace('/\,/'' 'trim($k));
$k preg_replace('/\s+/'' 'trim($k));
$terms explode(' 'trim($k));

$sql '(';
while(list(
$i$v) = each($terms)) {

   if (
$i 0) {
      
$sql .= 'OR ';
   }

    
$sql .= "(last_name LIKE '%{$v}%' OR first_name LIKE '%{$v}%') ";
}
$sql .= ')';

$sql "SELECT ID FROM table_name WHERE {$sql}";
echo 
$sql
idx is offline   Reply With Quote