Search for the next date in the database

0

I am creating a mysql table where it contains the date of an event. The question is as follows: if in the current day there is an event it is highlighted otherwise the next day. would you have any idea how to do it? The query for the current day would be more like fetching the following if it does not have the current day.

$data_atual = date('Y-m-d');
$resultado_evento = mysql_query("SELECT * FROM agenda WHERE data like '%$data_atual%'");
while($linhas_evento = mysql_fetch_array($resultado_evento)) {
    echo "nome " . $linhas_evento['nome'] . "<br>";
}
    
asked by anonymous 26.08.2016 / 19:29

1 answer

1

Use greater equal and set a limit to 1, if you have an equal date today, show it, or show the next date. Do not forget to give an ORDER BY by date.

$data_atual = date('Y-m-d h:i:s');
$resultado_evento = mysql_query("SELECT * FROM agenda WHERE data >= '$data_atual' ORDER BY data ASC LIMIT 1");
    
26.08.2016 / 20:26