I want to let user click the table header to sort the table, but can just set the ascending order, can not set the descending order in the same table header. following is the function I used,
just want to know how to call the function
function sortDistrictNamedescend($a, $b) {
if ($a->DistrictName == $b->DistrictName) {
return 0;
}
return ($a->DistrictName < $b->DistrictName) ? 1 : -1;
}
because I have already call function sortDistrictNameascend
, but I also need to descending sorting the table, when user click the table header.
function sortBy(sKey)
{
document.sortResultsForm.sSortBy.value=sKey;
document.sortResultsForm.submit();
}
function sortDistrictNamedescend($a, $b)
{
if ($a->DistrictName == $b->DistrictName)
{
return 0;
}
return ($a->DistrictName < $b->DistrictName) ? 1 : -1;
}
function sortDistrictNameascend($a, $b)
{
if ($a->DistrictName == $b->DistrictName)
{
return 0;
}
return ($a->DistrictName < $b->DistrictName) ? -1 : 1;
}
if($sSortBy=="District")
{
usort($tempArr, 'sortDistrictNameascend');
}
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<tr>
<td class="headTable" width=15%>
<a href="javascript:sortBy('District');"><font color=white>District</font</a>
</td>
<td class="headTable" width=15%>
<a href="javascript:sortBy('Group');"><font color=white>Group</font></a>
</td>
<td class="headTable" width=10%>
<a href="javascript:sortBy('RegID');"><font color=white>RegID</font></a>
</td>
<td class="headTable" width=10%>
<a href="javascript:sortBy('Name');"><font color=white>Name</font></a>
</td>
</tr>
</table>