Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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
按mysql和wordpress列对表中的数据进行排序_Mysql_Wordpress_Sorting_Html Table - Fatal编程技术网

按mysql和wordpress列对表中的数据进行排序

按mysql和wordpress列对表中的数据进行排序,mysql,wordpress,sorting,html-table,Mysql,Wordpress,Sorting,Html Table,我正在尝试按分数升序对表格进行排序 这是表格: 这是我正在使用的代码 $sql = "SELECT * FROM scores"; $myData = mysql_query($sql); echo "<table class='table table-hover table-bordered table-striped'> <tr> <th>Username</th> <th>

我正在尝试按分数升序对表格进行排序

这是表格:

这是我正在使用的代码

$sql = "SELECT * FROM scores";
  $myData = mysql_query($sql);

  echo "<table class='table table-hover table-bordered table-striped'>
        <tr>
        <th>Username</th>
        <th>Email</th>
        <th>Score</th>
        </tr>";

  while($record = mysql_fetch_array($myData)) {
        echo "<tr>";
        echo "<td>" . $record['id'] . "</td>";
        echo "<td>" . urldecode($record['email']) . "</td>";
        echo "<td>" . $record['score'] . "</td>";
        echo "</tr>";
   }
   echo "</table>";
?>
<?php
    $str="@";
    echo htmlentities($str);
?>
$sql=“从分数中选择*”;
$myData=mysql\u查询($sql);
回声“
用户名
电子邮件
分数
";
而($record=mysql\u fetch\u数组($myData)){
回声“;
回显“$record['id']”;
echo“.urldecode($record['email'])”;
回显“$record['score']”;
回声“;
}
回声“;
?>

更改您的
SQL
语句,以包含
ORDER BY
子句

$sql = "SELECT * FROM scores";
应该变成

$sql = "SELECT * FROM scores
        ORDER BY score ASC";

其中score是你想要排序的列,ASC是数据的顺序

在你的查询中使用order by。这个问题不应该被问到,在谷歌2分钟后,你就会发现你的答案堆栈溢出不是出于“我不能被纵火看我要问什么”的心态。你写那篇文章所花的时间要比回答问题所花的时间要多。我想我已经试过了,第一次就出错了。但这似乎奏效了,谢谢你的帮助。