mysql - How to alphabetical sort php while loop variable?
706
i am selecting an id from a table and then by id getting name of all members by their ids. Now the problem is that , how to sort name ($uname) alphabetically? It could be simple but i am stuck ..thanks for the help!! Code below -
$sql= mysql_query("Select DISTINCT(`Supervisor ID`) from `list` ");
while($row = mysql_fetch_array($sql))
{
$id = $row['Supervisor ID'];
$query = "SELECT `Name` from `list` WHERE `ID` = '$id' ";
$name = mysql_query($query);
$username = mysql_fetch_array($name);
$uname = $username['0'];
$Supervisor .="<OPTION VALUE=\"$uname\">".$uname.'</option>';
}
Answer
Solution:
ORDER BY
clause is used for any kind of sorting from database. So change your query in the loop like this:For more information: ORDER BY cluase
Let me know for further help.
Answer
Solution:
you can do it in single query, try this one..
Answer
Solution:
Use This:-
Sort your name Array Here Using
Click Here For Demo of Sort function
Create Option valus like this
Answer
Solution:
use
order by
clause for ascending order and desc for descending order