php - 在php中反转数组
问题描述
我正在尝试反转数组,以便它可以先在数据库中显示较新的条目,然后再显示较旧的条目。这是代码:
<?php
include_once('db/connection.php');
$query="select * from news";
$result=mysqli_query($conn,$query);
?>
<?php
while($rows=mysqli_fetch_array($result))
{
?>
<div class="container">
<div class="cust_bloglistintro">
<div class="row">
<div class="col-md-6 col-lg-4 cust_blogteaser" style="padding-bottom: 20px;margin-bottom: 32px;height: 750px;">
<div class="card" data-aos="fade-up" style="height: 700px;"><img class="card-img-top w-100 d-block" src="images/<?php echo $rows['thumbnail'];?>">
<div class="card-body">
<h4 class="card-title"><?php echo $rows['title']; ?> </h4><span style="font-family: 'Open Sans', sans-serif;font-size: 12px;margin-bottom: 5px;"><?php echo $rows['date']; ?></span>
<p class="card-text"><?php echo $rows['description']; ?></p><a class="card-link" href="<?php echo $rows['link']; ?>" target="_top">Read more...</a>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
解决方案
您可以在查询中使用 MySQL 的 ORDER BY 子句。
select * from news ORDER BY id DESC
推荐阅读
- typescript - 找不到名称“sendResponse”
- swift - XMLParser 在 Apple Watch 模拟器上工作,但在真实硬件上没有网络
- python - 使用 2 个不同的测量单位旋转 2d 网格中的一个点
- php - Laravel 资源控制器在成功更新/存储后不会重定向
- python - 尝试为每 6 次交互存储数组的每个值
- javascript - 为什么我的视频标签上的显示值没有按预期更新
- c++ - C++ 字符串变量不接受输入和制表符空格?
- c# - 没有注册财产例外,除了应该有
- css - 我的 theme.liquid 文件中是否有太多 if 语句?
- javascript - Electron 使用 Express React 模板引擎在构建后显示空白页面