View Single Post
Old 02-23-2007, 11:23 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
How about something like this:
PHP Code:
$string $_POST['search'];
/* split string at spaces */
$tok strtok($string" ");
$items = array();
/* fetch every item from the list */
while ($tok !== false) {
   
$items[]=$tok;
   
$tok strtok(" ");
}
/* create SQL statement */
if(count($items)){
  
/* theres somethign to search for */
  
$query="SELECT * FROM users WHERE ";
  foreach(
$items as $item){
    
/* we have no knowledge of how many items they've entered */
    
if(isset($been_here))
      
$query .= " OR ";
    
/* we dont know if they entered "firstname lastname" or "lastname firstname" */
    
$query .= "firstname LIKE \"%$item%\" OR lastname LIKE \"%$item%\"";
    
$been_here 1;
  }

__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 02-24-2007 at 02:44 AM.
redhead is offline   Reply With Quote