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 hexo+github部署博客
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?