-1
I have a system that uses dates for registration and I separate the date by a explode formed by arrays and record them in a database, but when I do the query that searches them by order, the order embarrasses.
Following are examples of the code ->
<?php
$listar = new USER();
$stmt = $listar->runQuery("SELECT * FROM horario ORDER BY dia,mes,ano DESC LIMIT 5");
$stmt->execute();
$Row=$stmt->fetchAll(PDO::FETCH_ASSOC);
Recent dates : 08/11/2018
As you can see is not picking up the records as it should, please need help is my TCC!!!
I think it is because you are giving a DESC ordination only in the year. Try to change to: ORDER BY DESC day, DESC month, DESC year. But if you made a date field with the full date would be easier for you to deal with later.
– Samanta Silva
Also remember that you are sorting by date, where you have equal dates, but no time, so mysql knows which is the most recent or oldest data. then it continues the increasing ordering by the other fields. and maybe that’s why you’re having this shuffling.
– Samanta Silva
I recently made an alternative table to record all dates, times to use the "Time Ago", but only this, in case I saved in the bank being as day, month and year because it is not only the site that feeds the bank, has more 2 fronts ( Android, Desktop ) who will also use the bank and it became easier to separate the date for them( I’m not making them ), but your SELECT example below solved my problem!! Thank you in advance.
– Geovanii Amaral