【问题标题】:ORDER BY not working in while() loop, PHPORDER BY 不在 while() 循环中工作,PHP
【发布时间】:2019-10-24 14:29:02
【问题描述】:

我正在制作一个文章列表,我希望它按“ASC”(升序)列出,但它不起作用。

我尝试过ORDER BYsort();,但我认为我做了sort();错了。

这是从数据库中选择的部分

include_once("config.php");
$result2 = mysqli_query($mysqli, "SELECT * FROM posts ORDER BY post_id");
error_reporting(0);
?>

这就是while();循环

<?php while ($entry = mysqli_fetch_array($result2)) { ?>

我真的希望它从 id 提升列表。

如果你想知道,基本上我在while循环之后做的是使用$entry['datafromdatabase']从表中调用数据

【问题讨论】:

  • 你能提供更多代码吗?请添加更多代码和解释。 @dhentris 答案应该可以正常工作,因为您不添加 extra steps...
  • post_id和你在问题中提到的id一样吗?

标签: php mysql xampp


【解决方案1】:

你可以试试这个

$result2 = mysqli_query($mysqli, "SELECT * FROM posts ORDER BY post_id ASC");

这对我有用。

【讨论】:

  • 你能帮我解决这个问题吗?对不起,我是初学者
  • 将数组放入变量 $entry = mysqli_fetch_array($result2);然后把它写在你的html文件中
  • 什么是 $column?
  • 这与OP的查询相同。 ORDER BY 默认为升序。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-27
  • 1970-01-01
  • 1970-01-01
  • 2016-01-11
  • 1970-01-01
相关资源
最近更新 更多