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

时间:2017-06-02 15:30:32

标签: 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>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);
?>

1 个答案:

答案 0 :(得分:0)

更改SQL语句以包含ORDER BY子句

$sql = "SELECT * FROM scores";

应该变成

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

分数是您要排序的列,而ASC是数据的顺序