Php 如何设置让用户点击表头改变排序顺序的功能
我想让用户点击表头对表格进行排序,但只能设置升序,不能在同一表头设置降序。下面是我使用的函数Php 如何设置让用户点击表头改变排序顺序的功能,php,javascript,Php,Javascript,我想让用户点击表头对表格进行排序,但只能设置升序,不能在同一表头设置降序。下面是我使用的函数 function sortBy(sKey) { document.sortResultsForm.sSortBy.value=sKey; document.sortResultsForm.submit(); } function sortDistrictNamedescend($a, $b) { if ($a->DistrictName == $b->DistrictN
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');
}
我看到了您的SortDistrictNameDescent函数,但看不到您在哪里调用它。只想知道如何调用函数SortDistrictNameDescent$a,$b{if$a->DistrictName===$b->DistrictName{return 0;}返回$a->DistrictName<$b->DistrictName?1:-1;},因为我已经调用了函数sortDistrictNameascend,但是当用户单击标题时,我还需要对表进行降序排序。