所以我使用 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 關注
- 150 瀏覽
添加回答
舉報
0/150
提交
取消