0

Im having a issue with comparing dates below is the code. it shows all rows even dates that have passed todays date. The Date field is set as date in sql.

<?php
$con = mysql_connect("localhost","myusername","mypassword");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("mydatabase", $con);


$todays_date = date("Y-m-d");
$today = strtotime($todays_date);


$result = mysql_query("SELECT * FROM event where 'date' < $today");


   while ($row = mysql_fetch_array($result)) {
   echo "<tr>";
   echo "<td>" . $row['Id'] . "</td>";
   echo "<td>" . $row['Date'] . "</td>";
   echo "<td>" . $row['ArtistDate'] . "</td>";
   echo "<td>" . $row['Artist'] . "</td>";
   echo "<td>" . $row['ImagePath'] . "</td>";
   echo "<td>" . $row['ImgLink'] . "</td>";
   echo "<td>" . $row['IncFile'] . "</td>";
   echo "</tr>";


   }
   echo "</table>";

   mysql_close($con);
?>
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by diafol
0

Try this SQL - backticks about the date - not single quotes. If you're using date format in DB, why using strtotime? date() should do everything you need.

SELECT * FROM event where `date` < '$today'
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.