You will need to pass the table column too, so you can use it in the order by (just like ASC/DESC).
pritaeas
Posting Prodigy
9,316 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,467
Skill Endorsements: 86
<th><a href='?sortcolumn=logid&sortcostcode=" . ($order == 'DESC' ? 'ASC' : 'DESC' ) . "'>logid</a></th>
If you want a jQuery solution, I can recommend datatables.net.
pritaeas
Posting Prodigy
9,316 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,467
Skill Endorsements: 86
You shouldn't have changed line 7. Instead add a line like it to retrieve the sortcolumn, and include it in the query. Just like you use $_POST['sortCostCode'] you can use $_POST['sortcolumn'], like this:
$order = (isset($_POST['sortCostCode']) && strcasecmp($_POST['sortCostCode'], 'desc') == 0) ? 'DESC' : 'ASC';
$column = isset($_POST['sortcolumn']) ? $_POST['sortcolumn'] : 'logid';
$query = "SELECT * FROM `Humeur_log` ORDER BY `$column` $order LIMIT 0,30";
pritaeas
Posting Prodigy
9,316 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,467
Skill Endorsements: 86
liste.php?sortcolumn=logid&sortcostcode=%22%20.%20($order%20==
It opens liste.php with GET parameters sortcolumn and sortcostcode (so change $_POST to $_GET). The reason you get the garbage after, is because the lines 15-19 are not properly quoted. They should look like this:
<th><a href='?sortcolumn=logid&sortCostCode=<?php echo $order == 'DESC' ? 'ASC' : 'DESC'; ?>'>logid</a></th>
Also, see sortCostCode. PHP is case sensitive, so how you write it should exactly match. Currently line 8 and 15 use a different sortcostcode. Make sure they match.
pritaeas
Posting Prodigy
9,316 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,467
Skill Endorsements: 86
The query failed. To find out why, do this:
$result = mysql_query($query) or die(mysql_error());
Fix the typo on line 2 (GEST).
Oh, line 17 uses Date while line 27 uses datelog. Use the correct one. Same with 18 and 28.
pritaeas
Posting Prodigy
9,316 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,467
Skill Endorsements: 86
Question Answered as of 6 Months Ago by
pritaeas