I have designed a basic website using HTML, CSS, javascript, and php for backend.
On the website, after a user logs in, he gets an option to buy some items(can be a single item or may be multiple items depending on the users choice).
My question is that if there are multiple number of users active on the website at any point of time, then is it possible to add the prices of all of the items bought by all of the active users and get the output in a single variable.
For example let's say only 2 users namely user 'a' and user 'b' are active at a given time and if user 'a' buys 2 items worth rupees 20 and 100, and the other user 'b' buys 3 items worth rupees 100, 200, and 300 then I want to add all the prices of items bought by both the users i.e. user 'a' and user 'b' in a variable named 'total' and its value should be 20+100+100+200+300=720.
Please guide on how to do this if it is possible to do so. Also if not possible in a variable then can it be possible to do so using the database.
For a real time, you should use WebSockets It makes your server and your client side in relation via messages (without refresh page)
Include on client side JS : https://developer.mozilla.org/fr/docs/Web/API/WebSockets_API
And Include on server side PHP : https://www.php.net/manual/fr/book.sockets.php
It's used by any live chats for example, you store data on your socket server, and at any modification received from a client, your server recalculate and send the update to all client,
and then a JS scrpit modificate the DOMDocument with the received message.