dqcz57269 2012-11-03 16:26
浏览 43
已采纳

按发布时间排序PHP回显输出

Ok, so. I have asked about 5 questions on stackOverflow today, you've all been so helpful.

Now, i'm a designer, learning to code, so bear with me.

I have a mySQL table, with a small CMS/Blog im building. I have it styled how I want to now. This is the code for the page.

$result = mysql_query("SELECT * FROM Blog");
while($row = mysql_fetch_array($result))
{
    echo "<h1>" . $row['Title'] . "</h1>";
    echo "<br>";
    echo "<h2>" . "Posted on:   " . $row['Date'] . "</h2>";
    echo "<br>";
    echo "<img src='".$row['Image']."'/>";
    echo "<br>";
    echo $row['Message'];
    echo "<br>";
    echo "<br>";
}

I'm still working on it so its all good.

What I want to know is, this code is outputting my sql data into a page. Is there any way of telling the page what order to echo the data, for instance. in my SQL table i have:

2012-11-03 16:16:06     This is my First Blog Post  This is the first message of the first blog post. ...   http://blog.gettyimages.com/wp-content/uploads/201.

and next is

2012-11-03 16:17:29     This is my Second Blog Post     This is the second message of the Second Post, You...   http://www.aviation-images.com/user/zooms/118/451n...

How can i tell the page to Always display the most recent post at the top, and older ones below.?

  • 写回答

3条回答 默认 最新

  • dongtan2603 2012-11-03 16:28
    关注

    Use order by in your query:

    $result = mysql_query("SELECT * FROM Blog ORDER BY Date DESC");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题