I think the question is very simple to the point of insanity, but I am still a newbie and I don’t even know how to ask Google correctly =)

There is a table in MySQL that in the future will have a few hundred thousand records. This table is constantly updated with new entries. Suppose a record has 2 values: 1) Number 2) UserID

It is necessary to add the entire column Number, where UserID = ID of the user session, after which the resulting figure to display on a specific page, for example in the user profile. I understand how to do this (although it’s not a fact that it’s true), I have already implemented this by outputting all the data into an array, after which the foreach loop adds all the numbers. The problem is that with each page refresh this request is sent. But I now have only 10-20 records in the table and I am sitting 1 on my local computer, this is done instantly. And what will happen if the site is large online and they constantly reap f5? Well, clearly nothing good.

Actually the question is how to implement all this correctly, so that the request is not sent every time the page is refreshed and there are no problems with overloading.

  • one
    Make 1 user 1 record by updating the value in it. - Visman
  • This option is considered specifically for this page. But the fact is that on the arc page I will need to display all these figures separately, in the form of a story. The simplest example: the history of account replenishment in your account. There you need to display all records with replenishments, where UserID = Session ID. - z0diac
  • This table is left as it is for the history output, and in the user table you add a field in which the total result will be changed when the account is refilled. - Visman
  • @ z0diac In general, to get the amount in SQL it would be enough to select sum(Number) from table where userid=1 or number for all users (by row per each) select userid, sum(Number) from table group by userid . It is much faster than any foreach. But of course, if you need to issue this figure all the time, then it makes sense to keep it ready in the user - Mike

0