提问者:小点点

如何只显示上次发送到数据库的帖子? phpMyAdmin


因此,我使用foreach循环从phpmyadmin中的数据库中获取数据,然后将其显示在indextest.php文件中,该文件具有以下代码:

  <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个答案

匿名用户

使用need this SQL查询withid DESC limit1:-

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