mysql - MySQLi + PHP sort by date and ID in descending order -


i'm looking mysql query sort items date in descending order. if finds 2 or more rows same date, sort them id in descending order.

this current code:

$sql = "select $rows $table order date desc"; 

it displays items in descending order date if there 2 items same date, displays them in ascending order id instead of descending.

example:

let's assume set of data:

id - date       - text 1  - 2017-01-01 - oldest 2  - 2017-01-02 - 2 3  - 2017-01-03 - morning 4  - 2017-01-03 - afternoon 5  - 2017-01-04 - latest 

the current code list as:

id - date       - text 5  - 2017-01-04 - latest 3  - 2017-01-03 - morning 4  - 2017-01-03 - afternoon 2  - 2017-01-02 - 2 1  - 2017-01-01 - oldest 

i want list this:

id - date       - text 5  - 2017-01-04 - latest 4  - 2017-01-03 - afternoon 3  - 2017-01-03 - morning 2  - 2017-01-02 - 2 1  - 2017-01-01 - oldest 

i don't want sort id because want add events happened in past , require me manually edit id of events after one.

sorting date not consider 2 events happen on same day @ different times. 1 higher id going 1 happened last.

i sort time , date potentially not have time data on past events , want keep consistent.

$sql = "select $rows $table order date desc, id desc"; 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -