I am currently stuck with my logic.
I have created a database table for snedimg messages
table messages looks like this
id | sender_id | reciver_id | msg | send_date |
1 | 2 | 6 | hello there i am testing | 2013-01-15
So what i am totally stuck with is the removing the message logic.
The problem what i dont understand how to solve is, lets say user with the id 6 gets the message, and removes it by id, that way who sent the message wont be able to see it either.
So i am a bit lost at this, if someone could give me a hint on a logic i would really be happy
EDIT WITH MORE EXPLAINED DETAILS
So the problem is
id | sender_id | reciver_id | msg | send_date |
1 | 2 | 6 | hello there i am testing | 2013-01-15
this is the table. User recives the message, reads it, and for some reason wants to remove it.
Probmel is the DELETE LOGIC, i know how to delete rows, what i dont know is how to solve the problem if the reciver deletes the message, the sender will be able to see it un the he/she deletes it.
For example on facebook they use archive instead of delete, this is the logic what i dont understand
Just set the reciver or sender id to -1 on deletion and have a check afterwards if both are -1 (or would be -1) delete that row.
e.g.
on deletion by reciver:
if ($sender_id == -1) {
$query = "DELETE FROM messages WHERE id=$id";
} else {
$query = mysql_query("UPDATE messages SET reciver_id=-1 WHERE id=$id";
}
mysql_query($query)
That way it would be still availabe until both delete it
Edit:
Just as additional thought for that solution:
You could set both to -1 instead of deleting it on the second user deletion so you got a kind of archive and delete too old ones by a cronjob.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With