0
In a PHP + Mysql application in which I need to store how many Likes + id’s of who gave like in a publication, I came up with a question about the logic.
Assuming that 2 users give like in the same post at the same time, and both run:
UPDATE te_anuncios
SET curtidasTotal = curtidasTotal + 1,
curtidasIds = curtidasIds + idNovo; //iria geral algo como '23, 31, 43, 44, 32...'
I need to treat this update in PHP, to add the ID of the new tanner, right?
<?php
$idsAtuais .= ", {$_SESSION['userId']}";
My fear is that while PHP treats the current Ids to concatenate into the database string, someone else gives a like and captures the values of the database without the ID being handled and overwrites it when it completes.
Is there a smarter way to inhibit this problem? Maybe run something directly on Mysql.
His concern is consistent, as there is clear competition in this case. However, the structure of its table, which I do not think is the ideal one, is what provides such a situation. Research relationships between tables and see how to implement the "many to many" relationship structure (in English, Many-to-Many).
– Woss