php片段:
mysqli_select_db($con,"dbtest");
$sql="SELECT * FROM w3school";
$result = mysqli_query($con,$sql);
echo "<ul id='myUL'>";
while($w3school = mysqli_fetch_array($result)) {
echo "<li id='".$w3school['id']."'>" . $w3school['LastName'] . "</li>";
}
echo "<ul>";
SCREEN OUTPUT看起来像这样:
id = 5;
id = 4;
id = 3;
id = 1;
id = 2;
我不明白为什么它不是1,2,3,4 ......
有什么建议吗? (任何规格信息只是让我知道)
答案 0 :(得分:0)
您的查询需要order by
。
SELECT * FROM w3school order by id
答案 1 :(得分:0)
您需要按照您想要按ID订购的方式使用订单 - &gt; 1,2,3,4 ...
SELECT * FROM w3school order by id asc;
或简单
SELECT * FROM w3school order by id; // no need to add asc, default asc
如果你想要6,5,4,3,2,1那么请使用desc之类的命令
SELECT * FROM w3school order by id desc;
您可以像这样使用多个订单
SELECT * FROM t1 ORDER BY key_part1 DESC, key_part2 ASC;
更多信息
https://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html