4
I have a table called AGENDA, where I have the fields, ID, Location, Date. Do the insertion and selection inside the database already managed to do correctly. But I can’t select the date in ascending order, showing the events that will happen first, and I wanted to restrict events to just the next 30 days. Have some command in php/mysql for that, or I would have to develop a function for that?
Solution after replies/comments:
Table structure:
id - Auto Increment
date - Date
Place - varchar
Code display.php:
<?php
include "configurar.inc";
// Capturando o ano atual para quando for selecionar o mês dos eventos não aparecer de todos os anos.
$dataatual = explode("/", date('d/m/Y'));
$anoatual = $dataatual[2];
// Supondo que quero o mês de maio (5)
$sql = "SELECT * FROM datas WHERE MONTH(data) = 5 AND YEAR(data) = $anoatual ORDER BY data ASC";
$query = mysql_query($sql);
echo "Proximos Eventos: ";
while($linha = mysql_fetch_array($query)) {
$datasemformato = $linha['data'];
$dataformatada = implode("/", array_reverse(explode("-", $datasemformato)));
echo "<br>";
echo "$dataformatada";
// Compara data e diz se o evento é hoje.
if(date('d/m/Y')==$dataformatada) {
echo " -> Esse evento é hoje.!";
}
// Compara a data e diz se o evento é amanhã.
if(date('d/m/Y', strtotime("+1 day"))==$dataformatada) {
echo " -> Esse evento será amanhã.!";
}
}
?>
If you want to view events for the next 30 days: WHERE data between NOW() and DATE_ADD(NOW(), INTERVAL 1 MONTH)
From what I’ve seen has already been solved your question, but if possible put the structure of your table for future searches of other users. You can help someone. I know you put the fields, but the structure itself of the fields ;)
– Marcelo Diniz