Split and search messages by older and newer

Asked

Viewed 249 times

4

I have a table. In her the 4 columns
ID high-increment,
id_user1 would be the id of the user who sent the message,
id_user2 either would be the id of the user who received and
mensagem the one who receives the message sent by id_user1 for id_user2.

Is there any way to search the latest for a mailing list?
I mean, we have the Whatsapp and several other applications that follow the same message list system, where they go up according to the latest.

inserir a descrição da imagem aqui

I know you can do it with a DESC, but wanted something dynamic that shows up in real time and that was separated by ide as the applications and not ID 1 now and then ID 1 again in 4 or 5 and etc... each one separate and without showing the same id_user1 again..

They understood?

  • 1

    Add a field to your table with the upload date. Then checarPorNovasMensagens.php place an argument stating the last time a message was received. At the time of giving select Simply select all messages whose sending time is later than the last received message. Alternatively, you can select the last time the message was sent to a field in your user table.

  • I advise to use UTC and convert Timezone later, to prevent headaches!

  • but "order by data desc" would only be a filter to sort the records in descending chronological order, so that within each record you can implement it in any way, containing or not information like ID and the like.

  • I don’t know anything, but explains one thing, how does p/ my whattssap appear "fucking..." instead of writing.... kkkkkkk

1 answer

1

By adding a column to your table, you can sort at will using the SELECT, without even touching each record in the table. For example:

ALTER TABLE tabela ADD data_enviada DATETIME;

Then you could write a query like this:

SELECT
   ID,
   id_user1,
   id_user2,
   id_mensagem
FROM
   tabela
ORDER BY
  data_enviada

So it is ordered by date, but not necessarily showcase the date.

Browser other questions tagged

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