I have a script in PHP like this one:
if(isset($_GET["ord"]))
{
switch($_GET["ord"])
{
case 1: $ord = "name ASC";
break;
case 2: $ord = "surname ASC";
break;
case 3: $ord = "date ASC";
break;
case 4: $ord = "zone ASC";
break;
case 5: $ord = "latency DESC";
break;
default: $ord = "name ASC";
break;
}
}
else
{
$ord = "name ASC";
}
And using it in code like this:
$res = mysql_query("SELECT people.name AS Name, surname, date, zone, latency FROM people WHERE online=1 ORDER BY $ord");
$content->ADD('<table class="online"><tr><th><a href="?s=online&ord=1">Name</a></th><th><a href="?s=online&ord=2">Surname</a></th><th><a href="?s=online&ord=3">Date</a></th><th><a href="?s=online&ord=4">Zone</a></th><th><a href="?s=online&ord=5">Latency</a></th></tr>');
while ($resss = mysql_fetch_array($res))
{
$content->ADD('<tr><td align="center">'.$resss["name"].'</td>');
$content->ADD('<td>'.$resss["surname"].'</td>');
$content->ADD('<td>'.$resss["date"].'</td>');
$content->ADD('<td>'.$resss["zone"].'</td>');
$content->ADD('<td>'.$resss["latency"].'</td>');
$content->ADD('</tr>');
}
It is actually working quite awsome but I have problem when I need to change ASC and DESC sorting - so my question is how to rewrite my script to also be in acs/desc sorting available in outup data? Thank you.
mysql_*functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information.