我正在网站上构建一个便笺系统,现在用户可以使用PHP将便笺发布到MySQL数据库,然后PHP将其打印在页面上。但是,当他们打印/回显时,最早的显示在最前面,但我要显示最新的在列。我也希望将它们限制为10个,因此页面上仅显示10个。这是我的PHP代码,将非常感谢您的帮助:
// initialize some variables $notedisplaylist = ""; $myObject = ""; $result = mysql_query("SELECT * FROM notes WHERE note_author_id='$u_id' ORDER BY date_time"); while($row = mysql_fetch_array($result)){ $note_title = $row["note_title"]; $note_body = $row["note_body"]; $date = $row["date_time"]; $notedisplaylist .= '<h2>' . $note_title . '</h2><br /><p>' . $note_body . '</p><hr /><p>Noted: ' . $date . '</p><hr /><br />'; }
这应该做到:
$result = mysql_query("SELECT * FROM notes WHERE note_author_id='$u_id' ORDER BY date_time DESC LIMIT 0, 10");