0
我需要創建一個函數,只顯示當前日期的文章。 這裏是我創造:Php僅獲取今日文章?
function lastnews() {
$id = mysql_real_escape_string ($id);
$date = date('d');
$sql = 'SELECT * FROM posts WHERE post_status = "publish" AND post_date = "$date" ORDER BY post_date DESC LIMIT 3';
$res = mysql_query($sql) or die (mysql_error());
if (mysql_num_rows($res) !=0):
while ($row = mysql_fetch_assoc($res)) {
$title = $row['post_title'];
echo '<li><a href="post.php?id='.$row['id'].'">'.$title.'</a></li>';
}
endif;
} // end
但是,這是行不通的。日期在數據庫中的formt是:
Y-m-d H:i
感謝您閱讀本
謝謝你的回答。 – Meo
這很快。我在想同樣的事情,但檢查語法:-( - 會提示這也是:'... LIKE'_ $ date _%''。 – Smamatti