I’m trying to construct a ‘new comments’ feature where the user is shown the number of new comments since the last visit.
I’ve constructed a ‘Views’ table that contains the topic id, the user id and a timestamp. What’s the best way of updating the timestamp every time the user visits that topic or inserting a fresh row if one doesn’t exist? At the moment I have:
REPLACE INTO Views (MemberID, TopicID, Visited)
SET ('$_SESSION[SESS_MEMBER_ID]', '$threadid', '$t')
WHERE MemberID = $_SESSION[SESS_MEMBER_ID] AND TopicID = $threadid
However, this does not work. Is it possible to do this in one query?
Try replacing
SETwithVALUES. The syntax is:Edit: Note that this only really works if you have set
MemberIDandTopicIDas a unique key in your table. If you do this, then you should just be able to do either:or
(of course, you should be using proper placeholders so Little Bobby Tables doesn’t make a visit and destroy your database)