i have select menu on website displays available countries. countries come mysql table contains 10 countries, in random order. know how retrieve countries table , output them in html select menu php.
however, wondering code-wise the efficient way when want pick two specific countries appear on top of options list, other 8 countries listed underneath? use little sql , php possible achieving goal.
let's have following table "countries":
id name 1 united states 2 france 3 brazil 4 puerto rico 5 india 6 australia 7 italy 8 denmark 9 south africa 10 oman i output countries in select menu , want list start denmark , india (with ids option values).
my goal:
<select> <option value="8">denmark</option> <option value="5">india</option> // ... other 8 countries underneath, in no specific order </select> the basic sql query retrieving countries be:
select id, name countries how need proceed achieving goal best?
if want alphabetical order followers, can use statement
select id, name countries order id=8 desc, id=5 desc, name asc
Comments
Post a Comment