How to set the function to make user click the table header to change sorting order
<p>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,</p>

<p>just want to know how to call the function </p>

<pre><code>function sortDistrictNamedescend($a, $b) { 
    if ($a-&gt;DistrictName == $b-&gt;DistrictName) { 
        return 0; 
    } 
    return ($a-&gt;DistrictName &lt; $b-&gt;DistrictName) ? 1 : -1; 
}
</code></pre>

<p>because I have already call function <code>sortDistrictNameascend</code>, but I also need to descending sorting the table, when user click the table header. </p>

<pre><code>function sortBy(sKey)
{
   document.sortResultsForm.sSortBy.value=sKey;
   document.sortResultsForm.submit();
}

function sortDistrictNamedescend($a, $b)
{
    if ($a-&gt;DistrictName == $b-&gt;DistrictName)
    {
        return 0;
    }
    return ($a-&gt;DistrictName &lt; $b-&gt;DistrictName) ? 1 : -1;
}

function sortDistrictNameascend($a, $b)
{
    if ($a-&gt;DistrictName == $b-&gt;DistrictName)
    {
        return 0;
    }
    return ($a-&gt;DistrictName &lt; $b-&gt;DistrictName) ? -1 : 1;
}

if($sSortBy=="District")
{
   usort($tempArr, 'sortDistrictNameascend');
}


&lt;table border="0" width="100%" cellspacing="2" cellpadding="2"&gt;
    &lt;tr&gt;
        &lt;td class="headTable" width=15%&gt;
            &lt;a href="javascript:sortBy('District');"&gt;&lt;font color=white&gt;District&lt;/font&lt;/a&gt;
        &lt;/td&gt;
        &lt;td class="headTable" width=15%&gt;
            &lt;a href="javascript:sortBy('Group');"&gt;&lt;font color=white&gt;Group&lt;/font&gt;&lt;/a&gt;
        &lt;/td&gt; 
        &lt;td class="headTable" width=10%&gt;
            &lt;a href="javascript:sortBy('RegID');"&gt;&lt;font color=white&gt;RegID&lt;/font&gt;&lt;/a&gt;
        &lt;/td&gt; 
        &lt;td class="headTable" width=10%&gt;
            &lt;a href="javascript:sortBy('Name');"&gt;&lt;font color=white&gt;Name&lt;/font&gt;&lt;/a&gt;
        &lt;/td&gt; 
    &lt;/tr&gt;
&lt;/table&gt;
</code></pre>
