【问题标题】:Sorting Data in Table by Column mysql and wordpress按列排序表中的数据mysql和wordpress
【发布时间】:2017-11-04 01:51:20
【问题描述】:

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

这是表格:

这是我正在使用的代码

$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);
?>

【问题讨论】:

  • 在查询中使用 ORDER BY。
  • 这个问题不应该被问到,在谷歌 2 分钟,你会发现你的答案堆栈溢出不是“我不能被认为是我要问这个问题”的心态。与google.co.uk/… 相比,您写该帖子将花费更多时间来回答

标签: mysql wordpress sorting html-table


【解决方案1】:

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

$sql = "SELECT * FROM scores";

应该变成

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

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

【讨论】:

  • 那行得通。我虽然已经尝试过,但第一次遇到错误。但这似乎行得通,感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2012-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-05
相关资源
最近更新 更多