Sorting Mysql List

Ask about a PHP problem here.
Post Reply
dareskog
Posts: 12
Joined: Sat Jan 21, 2012 2:49 am

Sorting Mysql List

Post 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]
Fidbeck
Posts: 147
Joined: Tue Sep 25, 2012 11:40 pm

Re: Sorting Mysql List

Post by Fidbeck »

You simply have to add to your query [syntax=php]ORDER BY `name` DESC[/syntax]
Post Reply