Reputation: 107
This is kind of complex to me, so I hope someone can help me out.
I have a table that shows messages which are stored in a database. These messages works like a commentbox. The database that holds these messages contains the following tables:
id, name, message, urlUserOne, urlUserTwo, urlUserThree.
id is set to auto increment to create a unique number for each message. name is used to store the name of the user who wrote the message. message holds the message that is written.
The messages shown on the screen will be red by a fixed group of users, that's why I have the urlUserOne / urlUserTwo / etc added. They hold a text that says whether this user has red the message or not.
Beneath the message three photos are shown, one for each user. What I want is that, when an user clicks on his photo, the data that is stored in the database will change, but just for this person, so other users know that he has red the message. The text for the other users needs to stay unchanged, just the text for that user for that specific message needs to change.
How can I accomplish this? Hope someone can help!
Upvotes: 0
Views: 121
Reputation: 1451
First of all, columns in DB for each user should be boolean (TRUE for read, FALSE for unread).
Then: Add a element to each photo, for example:
HTML
<a href="read.php?id=[MESSAGE_ID]&user=user1"><img src="pic_user1.jpg" ... /></a>
<a href="read.php?id=[MESSAGE_ID]&user=user2"><img src="pic_user2.jpg" ... /></a>
etc...
Then, in read.php
PHP
$sql = "UPDATE table_messages SET ".$_GET['user']." = true WHERE id = ".$_GET['id'];
execute_query($sql)
Let me know if it was useful.
Upvotes: 1