如何只显示最后发送到数据库的post? PHP管理员

How to display only the last post sent to the database? PHPMYADMIN

所以我在 phpmyadmin 中使用 foreach 循环从我的数据库中获取数据,然后将其显示在我的 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; ?>

问题是它获取了数据库中的所有 post,但是我只想获取发送到数据库的最后一个 post(最后一行)?这可能吗?谢谢

使用需要此 SQL 查询 id DESC LIMIT 1:-

SELECT * FROM TABLE t ORDER BY t.id DESC LIMIT 1