Sort array by Country Name not Country Code
-
I need to sort my result by country NAME and not the Country Code. Right now the list shows Spain and Mexico BEFORE United Kingdom. and I need the country list to be alphabetical by country name.
Here is my code:
<div class="forminner"> <h2>International Dealers</h2> <select class="dealers" name="mbn_country" id="mbn_country" onchange="myFunction()"> <option value="" selected="selected">Select Country</option> <?php $countries = new Pod('dealers'); $countries ->findRecords(country,-1); $total_states = $countries->getTotalRows(); //initialize data array $country_data = array(); //loop through all records and load into data array while ($countries->fetchRecord()) { $country = $countries->get_field('country'); $location_data = array( 'country'=> $countries->get_field('country') ); $location_data = array_unique($location_data); $country_data[0][$country][] = $location_data; } ?> <?php foreach ( $country_data[0] as $country => $countries ) : //loop through US locations by state ?> <?php $countries = array_unique($countries); foreach ( $countries as $country ) : if(($country['country'] != "") AND ($country['country'] != "US")) { ?> <option value="<?php echo country_code_to_country($country['country']); ?>"><?php echo country_code_to_country($country['country']); ?></option> <?php } endforeach; ?> <?php endforeach; ?> </select> </div>What am I doing wrong?
Thanks!
Viewing 15 replies - 1 through 15 (of 15 total)
Viewing 15 replies - 1 through 15 (of 15 total)
The topic ‘Sort array by Country Name not Country Code’ is closed to new replies.