View Single Post
Old 07-18-2005, 04:00 PM   #4 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Okay so you're making a form that where the user inputs search terms and those search terms are applied to the entries in a database right?
So the initial Array (we'll call it $results_array) would be filled with all the entries in the database. Since you can't hand code a hundred search queries you need to seperate out the searching from the normal flow. You have the users search terms in an array called $query_array.
You want to loop over query_array with a function that compares each value of results_array to a term from query_array and returns an array containing the matches.
PHP Code:
function reduce$results_array$search_term ){
 
$new_results = array();
 foreach( 
$results_array as $item ) {
  if (
preg_match ("/$search_term/i"$item)) {
   
$new_term[] = $item;
  }
 }
 return 
$new_results;

Now since that array will get smaller each time you run reduce with different terms, at the end of query_array, results_array will only contain entries that match all of the search terms.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote