How to sort by column header dynamically in the table ?
Table should be sorted by all column.
<?php
$order = (isset($_POST['sortCostCode']) && strcasecmp($_POST['sortCostCode'], 'desc') == 0) ? 'DESC' : 'ASC';
$query = 'SELECT * FROM `Humeur_log` ORDER BY `Humeur_log`.`logid` DESC LIMIT 0 , 30' . $order;
$result = mysql_query($query);
?>
<tr>
<th><a href='?sortcostcode=" . ($order == 'DESC' ? 'ASC' : 'DESC' ) . "'>logid</a></th>
<th><a href='?sortcostcode=" . ($order == 'DESC' ? 'ASC' : 'DESC' ) . "'>Prenom</a></th>
<th><a href='?sortcostcode=" . ($order == 'DESC' ? 'ASC' : 'DESC' ) . "'>Nom</a></th>
<th><a href='?sortcostcode=" . ($order == 'DESC' ? 'ASC' : 'DESC' ) . "'>Date</a></th>
<th><a href='?sortcostcode=" . ($order == 'DESC' ? 'ASC' : 'DESC' ) . "'>Humeur</a></th>
</tr>
<?php
while($rows=mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $rows['logid'] . "</td>";
echo "<td>" . $rows['prenom'] . "</td>";
echo "<td>" . $rows['nom'] . "</td>";
echo "<td>" . $rows['datelog'] . "</td>";
echo "<td>" . $rows['Humeur'] . "</td>";
echo "</tr>";
}
?>