i need to create a function that will display the articles of the current date only.
Here is what i have created:
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
But this is not working. the formt of date in database is :
Y-m-d H:i
Thank you for reading this
You need to specify the entire date (
date('Y-m-d')) and the query should sayAND post_date > '$date'because it includes a time. You can also sayAND post_date > CURRENT_DATE.