data field with direct order by in mysql displays a result and php exits differently

Asked

Viewed 91 times

0

I’m trying to display a query ordered by month field date, in the phpmyadmin the query comes out right and when I display the result of the same query with php the date comes out of the correct order.

consultation:

"select calendario.id_calendario, calendario.id_download, eventos.id_evento, eventos.descricao, str_to_date(concat(dia, '/', mes, '/', ano) , '%d/%m/%Y') as data
from calendario 
inner join eventos on calendario.id_evento = eventos.id_evento
order by month(data) asc , eventos.descricao asc"

mysql displays like this (correct) inserir a descrição da imagem aqui

and in php displays like this inserir a descrição da imagem aqui

The only difference is that I format the date in php for dd/mm/aaaa but this is after the consultation, someone has been through this?

  • It’s not easier just to use one date_format()? do not need to convert a date field to date.

  • There are three int fields (day, month and year) I use so because I have a calendar function that issues payment guides based on the "day" field that anticipates payment dates in the case of Saturdays, Sundays and holidays. And also because the customer wants to enter only with the day in time to register the events, but as I have to keep the registered events for up to 60 days at the time of displaying the listing of events if I do not put the full date there is no way to differentiate a same event that occurred in January from one that occurs in February.

  • You are using a CONCAT to join day, month and year, why not use ORDER BY calendar.mes, events.Description?? (I believe that the CSA is not necessary)

  • Good morning Thiago, really simplifies the query this way and the result is the same, only the queries are not being displayed through php with the same result that comes out in phpmyadmin

  • Ideally you put your code in PHP too, because the error should be there.

1 answer

2

I discovered the problem, it has nothing to do with php or mysql, I am using bootstrap with datatables and the API always initialized by column 0 then disabling the datatables parameters worked. Thank you all for your help.

$('#tabela1').dataTable( {
    order: [],
    columnDefs: [ { orderable: false, targets: [0] } ]
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.