3
Sort the latest ads registered in mysql, with the dates closest to the current date using PHP
Field type (date) in mysql is (date)
This is my query:
SELECT * FROM frame_anuncio WHERE ativo = 'Sim' ORDER BY destaque ASC LIMIT $inicio, $maximo;
3
Sort the latest ads registered in mysql, with the dates closest to the current date using PHP
Field type (date) in mysql is (date)
This is my query:
SELECT * FROM frame_anuncio WHERE ativo = 'Sim' ORDER BY destaque ASC LIMIT $inicio, $maximo;
4
Use the clause ORDER BY
in your query for this, this way:
SELECT id FROM table ORDER BY date DESC
Where:
id
= given to be returned;table
= table to be consulted;data
= date of registration in the database;DESC
= return in a decreasing way, from the largest to the smallest - using the logic of days: bring 30 before 29, just what you want.Based on the editing 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());
Thanks @Caesar for editing! I didn’t even know I had placed WHERE
in place of ORDER BY
.
Browser other questions tagged mysql order-by
You are not signed in. Login or sign up in order to post.
possible duplicate of How to get in SQL the last record inserted according to its date
– Laerte
@NULL No. It’s talking about Mysql, not SQL Server.
– Guilherme Oderdenge
This question can help you both to search in an orderly way and in a custom format How to sort a Mysql search with date in d-m-Y format?
– Erlon Charles
sql am doing so: $sql = mysql_query("SELECT * FROM frame_anuncio WHERE active = 'Yes' ORDER BY highlight ASC LIMIT $start, $maximo")or die(mysql_error();
– user3081
@user3081 You are ordering from minor to major trade the ASC for DESC.
– Laerte
@NULL This has nothing to do with it, man. This
destaque
, at first, has no relation to date.– Guilherme Oderdenge
If I exchange the ASC for DESC the ads in highlights are not at the top of the list...
– user3081
The highlight are ads with photos, IE, You have to list first the ads with photos after the rest...and everyone has to be active active
– user3081
what is the name of your date field?
– Erlon Charles
The name of the date field is: date and the type is: date
– user3081
@user3081 I edited my answer. See if it helps you. If it helps you, mark it as settled - I’ve been following you around and it seems like it’s not something you’re used to doing. If they help you, help us keep helping you. =)
– Guilherme Oderdenge
@user3081 until today I have not located where it marks as solved...?
– user3081
@user3081 In the answer, just below the up and down arrows that are located at the top left, there is a "positive" button. Click on it.
– Guilherme Oderdenge
On the left side of the answer you will see some gray bandstand signs, click on it
– Erlon Charles