Jason Posted May 12, 2012 Report Share Posted May 12, 2012 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 Quote Link to comment Share on other sites More sharing options...
Administrators simpilot Posted May 12, 2012 Administrators Report Share Posted May 12, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.