所以我使用 foreach 循环从 phpmyadmin 中的数据库中获取数据,然后将其显示在我的 indextest.php 文件中,该文件具有以下代码:<?php foreach ($posts as $post): ?> <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12 mt-4"> <h6> <span style="color: blue;">BREAKING NEWS</span> <span id="test" style="padding-left: 10px;"><?php echo date('F j, Y', strtotime($post['created_at'])); ?></span> </h6> <!-- HEADLINE --> <h1><strong><a href="/single_page_main.php?id=<?php echo $post['id']; ?>"><?php echo $post['title']; ?></a></strong></h1> </strong></h1></a> <!-- TEXT BODY --> <h4><?php echo $post['body']; ?></h4> <!--displays the full body --> <h4><?php echo html_entity_decode(substr($post['body'], 0, 150) . '...'); ?></h4> <a href="/single_page_main.php"> <div class="button_subs float-left mb-4">Read More</div></a> </div> <!-- IMAGE --> <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> <img src="<?php echo '/assets/images/' , $post['image']; ?>" style="width: 100%;"> </div><?php endforeach; ?>问题是它抓取数据库中的所有帖子,但是我只想抓取发送到数据库的最后一篇帖子(最后一行)?这可能吗?谢谢
1 回答

白猪掌柜的
TA贡献1893条经验 获得超10个赞
使用需要此 SQL 查询id DESC LIMIT 1
:-
SELECT * FROM TABLE t ORDER BY t.id DESC LIMIT 1
- 1 回答
- 0 关注
- 123 浏览
添加回答
举报
0/150
提交
取消