Jump to content

Sort airports by Location


Jason

Recommended Posts

I have a user select a country out of a select box, and then i want it to sort the airports that are in that country.

I have a $country variable, and by $allcountries variable:

$country = $_POST['location'];

$allairports = OperationsData::GetAllAirports($country);

... then i have a foreach statement

Am i doing that right? it does not sort the airports

Link to comment
Share on other sites

  • Administrators

If you look at the existing code you are making use of you will find that it does not use any extra input and is sorting by ICAO;

from OperationsData.class.php

public static function getAllAirports() {
	$key = 'all_airports';
	$all_airports = CodonCache::read($key);
	if ($all_airports === false) {
		$sql = 'SELECT * FROM ' . TABLE_PREFIX . 'airports
 ORDER BY `icao` ASC';
		$all_airports = DB::get_results($sql);
		if(!$all_airports) {
			$all_airports = array();
		}
		CodonCache::write($key, $all_airports, 'long');
	}
	return $all_airports;
}

You will probably have to write your own code, maybe something like;

public static function getAllAirports_sorted() {

 $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'airports
	 ORDER BY `country` ASC';

return = DB::get_results($sql);
}

The only issue you will probably have is that the country field for airports is not always automatically filled using the api server so the airports with a null value in that position will end up in one group within the variable.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...