You are here

function weather_search_autocomplete in Weather 6.5

Same name and namespace in other branches
  1. 7.3 weather.forms.inc \weather_search_autocomplete()
  2. 7 weather.forms.inc \weather_search_autocomplete()
  3. 7.2 weather.forms.inc \weather_search_autocomplete()

Given a partial string, search for a location or ICAO code matching that string.

Parameters

string $input The partial text to search for.:

1 string reference to 'weather_search_autocomplete'
weather_menu in ./weather.module
Implementation of hook_menu().

File

./weather.module, line 1200
Display <acronym title="METeorological Aerodrome Report">METAR</acronym> weather data from anywhere in the world

Code

function weather_search_autocomplete($input) {
  $matches = array();

  // In this query we search for ICAO code, country, and name of locations.
  $sql = "SELECT icao, country, name FROM {weather_icao}\n    WHERE icao LIKE UPPER('%%%s%%')\n    OR UPPER(country) LIKE UPPER('%%%s%%')\n    OR UPPER(name) LIKE UPPER('%%%s%%')\n    ORDER BY name ASC";
  $result = db_query_range($sql, $input, $input, $input, 0, 10);
  while ($match = db_fetch_object($result)) {
    $matches[$match->icao] = check_plain(sprintf("%s, %s (%s)", $match->name, $match->country, $match->icao));
  }
  print drupal_to_js($matches);
  exit;
}