我有一个网站,在该网站上显示数据库中的帖子更新,为此我们使用PHP和SQL,但当前显示的是最旧的帖子,而不是我要先显示最新上传的帖子。 < / p>
这是我的带有SQL查询的PHP代码
$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 } ?>
答案 0 :(得分:2)
只需将ORDER BY语句添加到您的查询中,如下所示:
$projectcat_query=mysql_query("select * from projectcat where id=3 ORDER BY id DESC");
答案 1 :(得分:2)
像这样更改您的第二个查询
$project_query=mysql_query("select * from projects where catid=$catid and status=1 order by id desc limit $limit ");