jwdbjbebefin jwdbjbebefin - 5 months ago 22
PHP Question

show only results after todays date

I have a database with dates and information associated with it. The problem I am having is that I am trying to get it to show only results that match after a certain date.

The way I have tried is using MySQL, if it is possible I would like an answer in mysqli which is more protected.

include("connect.php");
$query=("SELECT * FROM availability WHERE day >= date('Y-m-d')");
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['day'];?></td>
<td><?php echo $row['hour'];?></td>
<td><?php echo $row['booked'];?></td>
</tr>
<?php

Answer

You can use CURDATE() MySQL function to get and compare the current date with column.

Use it like this,

$query=("SELECT * FROM availability WHERE day >= CURDATE()");

As @tadman suggested

Do not use the mysql_query interface.
It’s so awful and dangerous that it was removed in PHP 7. Instead, the MySQLi or PDO_MySQL extension should be used.