I have a query $query = "SELECT * FROM sheet1 WHERE '$filter' LIKE '$search_field%'" This prints out a table while ($row = @mysql_fetch_array($result, MYSQL_ASSOC)){ // this just fills the empty cells if ($row['fname']==""){ $row['fname']=" "; } if ($row['sname']==""){ $row['sname']=" "; } if ($row['organisation']==""){ $row['organisation']=" "; } ?> <td width="71" class="right_line"> <?=$row['fname'];?> </td> <td width="45" class="right_line"><?=$row['sname'];?></td> <td width="437" class="right_line"><?=$row['organisation'];?></td> <? if (!$row['email']==""){ ?> <td width="165" class="end_cell"> <div align="left"><a href="view_details.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">details</a> | <a href="edit.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">edit</a> | <a href="delete.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">delete</a> I <a href="mailto:<?=$row['email']; ?>">email</a></div></td> <? } else { ?> <td width="171" class="end_cell"> <div align="left"><a href="view_details.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">details</a> | <a href="edit.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">edit</a> | <a href="delete.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">delete</a> I <a href="mailto:<?=$row['email']; ?>">empty</a></div></td> <? } ?> </tr> <? } } ?> but I have the three headings at the top which I want to use to re-order the results alphabetically. So when I click on surname it will re-reorder them aphebetically (z-a) and when I click on it again it will reverse it (a-z) <td class="right_line"><strong>Firstname</a></strong></td> <td class="right_line"><strong>Surname</strong></td> <td class="right_line"><strong>Organisation</strong></td> hope this is clear. Ross -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php