function weather_search_autocomplete in Weather 7
Same name and namespace in other branches
- 6.5 weather.module \weather_search_autocomplete()
- 7.3 weather.forms.inc \weather_search_autocomplete()
- 7.2 weather.forms.inc \weather_search_autocomplete()
Search for a location or ICAO code matching a partial string.
Parameters
string $input: The partial text to search for.
1 string reference to 'weather_search_autocomplete'
- weather_menu in ./
weather.module - Implement hook_menu().
File
- ./
weather.forms.inc, line 755 - Provide forms for configuration of weather displays.
Code
function weather_search_autocomplete($input) {
$matches = array();
// In this query we search for ICAO code, country, and name of locations.
$sql = db_select('weather_icao')
->fields('weather_icao', array(
'icao',
'country',
'name',
))
->orderBy('name', 'ASC');
$or = db_or()
->where('icao LIKE UPPER(:search)', array(
':search' => "%{$input}%",
))
->where('UPPER(country) LIKE UPPER(:search)', array(
':search' => "%{$input}%",
))
->where('UPPER(name) LIKE UPPER(:search)', array(
':search' => "%{$input}%",
));
$sql
->condition($or);
$sql
->range(0, 10);
$result = $sql
->execute();
foreach ($result as $match) {
$matches[$match->icao] = check_plain(sprintf("%s, %s (%s)", $match->name, $match->country, $match->icao));
}
drupal_json_output($matches);
}