Php HTML文本作为POST切换(有点像单选按钮)?

Php HTML文本作为POST切换(有点像单选按钮)?,php,html,post,Php,Html,Post,我的网站上有: 我希望能够通过按播放器、地图等对服务器进行排序。 以便更好地解释它;如果我按一次,我希望列表按降序排列,如果我再按一次,我希望列表按升序排列。我已经有了一个脚本,它与单选按钮一起工作,但是,这不适合我的设计。另外,我不想在点击文本后再按另一个按钮,我希望它立即改变排序 我的代码是: PHP: if(isset($\u POST['sort'])) { 如果($_POST['sort']=='Players downing') { uasort($serverArray,函数($

我的网站上有:

我希望能够通过按播放器、地图等对服务器进行排序。 以便更好地解释它;如果我按一次,我希望列表按降序排列,如果我再按一次,我希望列表按升序排列。我已经有了一个脚本,它与单选按钮一起工作,但是,这不适合我的设计。另外,我不想在点击文本后再按另一个按钮,我希望它立即改变排序

我的代码是: PHP:

if(isset($\u POST['sort']))
{
如果($_POST['sort']=='Players downing')
{
uasort($serverArray,函数($a,$b){
返回$b['Players']$a['Players'];
});  
}
如果($_POST['sort']=='Players singressing')
{
uasort($serverArray,函数($a,$b){
返回$a['Players']$b['Players'];
});  
}
}
还有HTML/PHP

    <form method="post">
    </select>
        Sort by:
        <input type="radio" name="sort" value="Players Descending">Players Descending
        <input type="radio" name="sort" value="Players Ascending">Players Ascending
    <input type="submit" name="submit" value="Filter"/>
    </form>

排序方式:
球员下降
球员上升

有没有人能告诉我怎么做?谢谢

如果您的数据存储在一个表中,这就是我所看到的 您发布的照片,请检查此js代码:

function sortTable() {
 var table, rows, switching, i, x, y, shouldSwitch;
  table = document.getElementById("myTable");
 switching = true;
 /* Make a loop that will continue until
 no switching has been done: */
 while (switching) {
   // Start by saying: no switching is done:
   switching = false;
   rows = table.getElementsByTagName("TR");
   /* Loop through all table rows (except the
   first, which contains table headers): */
   for (i = 1; i < (rows.length - 1); i++) {
  // Start by saying there should be no switching:
     shouldSwitch = false;
  /* Get the two elements you want to compare,
  one from current row and one from the next: */
  x = rows[i].getElementsByTagName("TD")[0];
  y = rows[i + 1].getElementsByTagName("TD")[0];
  // Check if the two rows should switch place:
  if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
    // I so, mark as a switch and break the loop:
    shouldSwitch= true;
    break;
  }
}
if (shouldSwitch) {
  /* If a switch has been marked, make the switch
  and mark that a switch has been done: */
  rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
  switching = true;
   }
 }
  }
函数排序表(){
var表,行,切换,i,x,y,shouldSwitch;
table=document.getElementById(“myTable”);
切换=真;
/*做一个循环,循环将持续到
未进行任何切换:*/
while(切换){
//首先说:未进行任何切换:
切换=错误;
行=table.getElementsByTagName(“TR”);
/*循环遍历所有表行(除
首先,它包含表标题):*/
对于(i=1;i<(rows.length-1);i++){
//首先说,不应进行切换:
shouldSwitch=false;
/*获取要比较的两个元素,
一个来自当前行,另一个来自下一行:*/
x=行[i].getElementsByTagName(“TD”)[0];
y=行[i+1].getElementsByTagName(“TD”)[0];
//检查两行是否应切换位置:
if(x.innerHTML.toLowerCase()>y.innerHTML.toLowerCase()){
//因此,标记为开关并断开循环:
shouldSwitch=true;
打破
}
}
如果(应切换){
/*如果开关已被标记,则进行更换
并标记开关已完成:*/
行[i].parentNode.insertBefore(行[i+1],行[i]);
切换=真;
}
}
}


现在用您的表名编辑“mytable”名称,当您单击列名(th标记)时,这应该可以工作。干杯

一两年前我就这样悬赏了我的问题。。可能是相关的你有没有尝试过用JavaScript排序?@代码见谢谢你的链接,我会仔细阅读。是的,我有,但是,我没有设法让它完全工作。Javascript是这种情况下的解决方案吗?谢谢您的帮助!:D
function sortTable() {
 var table, rows, switching, i, x, y, shouldSwitch;
  table = document.getElementById("myTable");
 switching = true;
 /* Make a loop that will continue until
 no switching has been done: */
 while (switching) {
   // Start by saying: no switching is done:
   switching = false;
   rows = table.getElementsByTagName("TR");
   /* Loop through all table rows (except the
   first, which contains table headers): */
   for (i = 1; i < (rows.length - 1); i++) {
  // Start by saying there should be no switching:
     shouldSwitch = false;
  /* Get the two elements you want to compare,
  one from current row and one from the next: */
  x = rows[i].getElementsByTagName("TD")[0];
  y = rows[i + 1].getElementsByTagName("TD")[0];
  // Check if the two rows should switch place:
  if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
    // I so, mark as a switch and break the loop:
    shouldSwitch= true;
    break;
  }
}
if (shouldSwitch) {
  /* If a switch has been marked, make the switch
  and mark that a switch has been done: */
  rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
  switching = true;
   }
 }
  }