I have a database table that i use to create a drop box, what I need is to figure out how to make a default selection (United States) appear first.
Here is my code,
$query="SELECT CountryID, Country FROM tblCountries ORDER BY Country DESC"; $result = $connection->query($query); if($result->num_rows>0){ while($row=$result->fetch_assoc()){ echo '<option value="'.$row['CountryID'].'"'; if($Country==$row['CountryID']){echo ' selected="selected"';} echo '>'.$row['Country'].'</option>'.PHP_EOL;
Any help is appreciated.
You can do it on the DB side with:
SELECT CountryID, Country, IF(Country = 'United States', 1, 2) AS mysort FROM tblCountries ORDER BY mysort ASC, Country ASC
That corrected it.
I am still fairly new to MySQL and PHP so I definitely appreciate the help.
Thank You