如何首先使用SQL和PHP显示最新上传的Post?

How to Show Latest Uploded Post first Using SQL and PHP?

我有一个网站,我在其中显示 post 数据库更新,我们为此使用 PHP 和 SQL,但目前最旧的 post 最先显示相反 我想先显示最新上传的 Post。

这是我的 PHP 代码和 SQL 查询

$projectcat_query=mysql_query("select * from projectcat where id=3 ");
  while($projectcat_data=mysql_fetch_assoc($projectcat_query))
       { $catid=$projectcat_data['id'];
         $limit=3;
          $project_query=mysql_query("select * from projects where catid=$catid and status=1 limit $limit ");
          while($project_data=mysql_fetch_assoc($project_query)) { ?>
    <div class="item <?php echo $projectcat_data['name']; ?>">
        <div class="picframe">
            <a class="" href="project/<?php echo str_replace(' ','-',$project_data['title']); ?>">
                <span class="overlay">
                    <span class="pf_text">
                        <span class="project-name"> <?php echo $project_data['title']; ?></span>
                    </span>
                </span>
            </a>
            <img src="images/services/<?php echo $project_data['image']; ?> ">
        </div>
    </div>
<?php } ?>

我的数据库 table 看起来像

只需将 ORDER BY 语句添加到您的查询中,如下所示:

 $projectcat_query=mysql_query("select * from projectcat where id=3 ORDER BY id DESC");

像这样更改您的第二个查询

$project_query=mysql_query("select * from projects where catid=$catid and status=1 order by id desc limit $limit ");