I’ve been trying to get my code to work exactly right, it works for the most part perfectly, with one exception, It’s sort of hard to explain in words, so I will try to show you what I’m dealing with.
First off, here’s my MYSQL QUERY so far, (which all needs to stay pretty much the same, or at least accomplish the same thing this does)
$notificationsq = mysql_query("SELECT N.*, P.*,
(CASE
WHEN
(N.action = 2 AND N.state = 0) THEN 1
ELSE N.state
END) AS state
FROM
notifications N,
posts P
WHERE N.userID='$session' AND
(N.action='1' OR N.action='2') AND
N.uniqueID=P.id AND
P.state='0'
GROUP BY N.uniqueID
ORDER BY N.state ASC, N.date DESC
");
Here’s my table setup for notifications (the code relating posts table is irrelevant for my problem)
http://i43.tinypic.com/2wd6phl.png
What each row represents (only the rows that aren’t self explanatory):
- uniqueID is the ID of the post that is to be notified about.
- action is what kind of notification it is. 1 is new post, 2 is new comment on post.
- state is whether or not the notification has been read or not. 0 is unread, 1 is read.
right now “state” only returns for posts (action = 1) that are unread (state = 0) however I want it to return “state” as 0 for the post if any of the posts get a new comment.
it’s like,
IF(action==2 AND state==0 WHERE uniqueID==uniqueID){state = 0}
how about this: