我试图按分数升序对表格进行排序。
这是表格:
这是我正在使用的代码
$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
声明以包含一个ORDER BY
子句
$sql = "SELECT * FROM scores";
应该变成
$sql = "SELECT * FROM scores
ORDER BY score ASC";
其中score是您要排序的列,ASC是数据的顺序
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句