I have a list in my database with several columns. And I want to sort them in PHP like this:
$sort = $_GET['sort'];
$sql = "SELECT * FROM users ORDER by ".$sort." DESC";
$result = mysql_query($sql) or die(mysql_error());
That works fine. But if the user clicks twice at a header for a column it should switch between ASC and DESC sort.
I'm going to implement this to a lot of files so I dont really want to change the original PHP code. I prefer to sort the data directly from the database query.
One way could be to define a variable
$int = 1;
and for every time the user sort a column:
The problem is that this variable will disappear every page refresh.
Someone got any similar solution?
As simple as possible =)