Hi,
This is my function for "search" autocomplete (drupal 6):

function autocomplete_getsearch($string = '') {
  $matches = array();
  
  $result = db_query("SELECT * FROM {search_index} WHERE LOWER(word) LIKE LOWER('%s%%')", $string);
  while ($row = db_fetch_object($result)) {
    $matches[$row->word] = check_plain($row->word);
  }
  
  print drupal_to_js($matches);
}

%s%% does not have the same effect on drupal 7. Is there a new way to put the %% signs after %s ? Thanks!

Comments

zoliky’s picture

any idea, please?

john morahan’s picture

Put the '%' in the string itself instead of the query. Like so:

  $result = db_query("SELECT * FROM {search_index} WHERE LOWER(word) LIKE LOWER(:term)", array(':term' => $string . '%'));

See http://api.drupal.org/api/function/user_autocomplete/7 for a complete example ;)