Sorting alphabetically
Posted: Thu May 20, 2004 8:42 am
I am successfully returning results from my database using the following code, but I want the results to be listed alphabetically by surname.
I have tried to add ORDER BY surname to $query without success.
I am now stuck as I'm not sure if the SORT function should be used somewhere in the while loop.
Any help would be much appreciated......
$query = "SELECT name.surname, name.forename, name.extention
FROM name
WHERE name.departmentID = ".$dept ;
$result = mysql_query($query);
while ($record = mysql_fetch_assoc($result)) {
while (list ($fieldname, $fieldvalue)=each($record)){
echo "$fieldvalue ";
}
echo"<BR>";
I have tried to add ORDER BY surname to $query without success.
I am now stuck as I'm not sure if the SORT function should be used somewhere in the while loop.
Any help would be much appreciated......
$query = "SELECT name.surname, name.forename, name.extention
FROM name
WHERE name.departmentID = ".$dept ;
$result = mysql_query($query);
while ($record = mysql_fetch_assoc($result)) {
while (list ($fieldname, $fieldvalue)=each($record)){
echo "$fieldvalue ";
}
echo"<BR>";