Page 1 of 1

Sorting Mysql List

Posted: Sat Feb 02, 2013 8:56 pm
by dareskog
Ive got a mysql table with a load of clients listed. The below script echos out each of them perfectly except I would like them to be sorted alphabetically. How can I do this with what I already have?
[syntax=php]
$client_list = mysql_query("SELECT * FROM clients");
while($row = mysql_fetch_array($client_list)){
echo "<a href='client.php?id=" . $row['client_id'] . "'>";
echo "<div id='client'><div id='name'>" . $row['client_name'] . "</div>";
if($row['client_r'] != 0){echo "<div id='r'>R</div>";}
if($row['client_s'] != 0){echo "<div id='s'>S</div>";}
if($row['client_d'] != 0){echo "<div id='d'>D</div>";}
echo "</div></a>";
}
[/syntax]

Re: Sorting Mysql List

Posted: Sun Feb 03, 2013 9:02 am
by Fidbeck
You simply have to add to your query [syntax=php]ORDER BY `name` DESC[/syntax]