sql - PHP: Compare Date -
i'm encountering following problem:
i'd compare today's date against dates in database, if isn't expired yet, show something... if dates in table expired, show 'no lecture scheduled @ time, return again'.
as first thing it's no problem, can't show text there aren't future dates...
here's code,
table: id, dateposted, date_course, title, body
$sql = "select * l order l.dateposted desc;"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $exp_date = $row['date_course']; $todays_date = date("y-m-d"); $today = strtotime($todays_date); $expiration_date = strtotime($exp_date); if ($expiration_date >= $today) { echo "<a href='courses.php'>" . $row['title']. "</a>"; echo "</br>"; } }
i'll assume you're using mysql. couple of small changes query , code should make work. should kind of filtering in query , not code.
$sql = "select * l date_course < now() , dateposted < now() order l.dateposted desc;"; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { echo "<a href='courses.php'>" . $row['title']. "</a>"; echo "</br>"; } } else { echo "no results available"; }
Comments
Post a Comment