Question :
Sort the last ads registered in mysql, with the dates closest to the current date using PHP
The field type (date) in mysql is as (date)
This is my query :
SELECT * FROM frame_anuncio WHERE ativo = 'Sim' ORDER BY destaque ASC LIMIT $inicio, $maximo;
Answer :
Use the ORDER BY
clause in your query for this, like this:
SELECT id FROM table ORDER BY date DESC
Where:
-
id
= given to be returned; -
table
= table to be queried; -
data
= record date in the database; -
DESC
= return decreasingly, from highest to lowest – using the logic of days: bring 30 before 29, just what you want.
Based on the edition of your post, do the following:
$sql = mysql_query("SELECT * FROM frame_anuncio WHERE ativo = 'Sim' ORDER BY destaque ASC, data DESC LIMIT $inicio, $maximo")or die(mysql_error());