I would let MySQL to the sorting and then just output what the query returns:
- PHP: Select all
$sort_key=mysql_escape_string($_GET['order']);
$query=mysql_query("SELECT * FROM files WHERE pos = '1' ORDER BY $sort_key;");
while($row=mysql_fetch_object($query)) {
// output
}
See if you can do something with that...