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.
select sum(Number) from table where userid=1or 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