Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何设置让用户点击表头改变排序顺序的功能_Php_Javascript - Fatal编程技术网

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,但是当用户单击标题时,我还需要对表进行降序排序。