Posted By

jzumbrun on 06/22/09


Tagged

search codeigniter


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

vali29
dantreacy
d0ri0
fadliawan


Code Igniter Search for multiple words


 / Published in: PHP
 

  1. /**
  2. * SearchEntries
  3. *
  4. * Options: Values
  5. * ---------------
  6. * words
  7. *
  8. * @param array $options
  9. * @return bool
  10. */
  11. function SearchEntries($options = array())
  12. {
  13.  
  14. $search_result = array();
  15.  
  16. $words = explode(" ", $options['words']);
  17.  
  18.  
  19. foreach($words as $word){
  20. if(isset($options['limit']) && isset($options['offset'])) $search_result = array_merge($search_result,$this->GetEntries(array('word' => $word, 'sortBy' => $options['sortBy'], 'sortDirection' => $options['sortDirection'], 'limit' => $options['limit'], 'offset' => $options['offset'])));
  21. else $search_result = array_merge($search_result, $this->GetEntries(array('word' => $word)));
  22. }
  23.  
  24. // unique multidimential array for entryid
  25. $new = array();
  26. $exclude = array("");
  27. for ($i = 0; $i<=count($search_result)-1; $i++) {
  28. if (!in_array(trim($search_result[$i]->entryId) ,$exclude)) {
  29. $new[] = $search_result[$i];
  30.  
  31. // key and value goes into array for testing
  32. $exclude[] = trim($search_result[$i]->entryId);
  33. }
  34. }
  35.  
  36. //print_r($new);
  37. return $new;
  38. }

Report this snippet  

You need to login to post a comment.