I am a beginner, and I will try to describe my question more correctly) Suppose there is a chat, 20 messages are displayed per page, navigation consists of 10 pages, that is, 20 messages from users are on each of these pages) the question is how to do it so that all messages not included in these pages are deleted automatically? I'm just thinking about it, have not yet started the implementation of this)

  • @NoProblems, If you received an exhaustive answer, mark it as accepted. - Nicolas Chabanovsky

1 answer 1

For example, when adding 201 messages, delete the record with the minimum index in the table.

1) we get the number of messages

SELECT COUNT(id_messages) FROM `messages` 

2) 10 pages of 20 messages = 200. If the number of messages from item 1> = 200, then we delete the first entry in the table

 DELETE FROM `messages` ORDER BY `id_messages` ASC LIMIT 1 

If the message has time, it is better to substitute the time column instead of id_messages .

3) Add a message

  • Can you give more details? - NoProblems
  • A little painted in the message, or you need all the details? - ilovetrancekrsk
  • Thanks, here I think I'll figure it out. thanks :) - NoProblems
  • @ HashCode community and who is this ??? - Artem
  • @ HashCode community and who is this ??? I accidentally ticked it when the rules were answered)) - ilovetrancekrsk