Reputation: 20078
i am working on a online forum like where anybody whether registered or un-registered user can comment on a particular topic/article etc...
so, when the user (registered/un-registered) leave their comments we have a process for approving by admin which is behind the scene....
so my question is, when the user leave their comments then i want to hold on to their comments till their comments approved by admin or till the session is alive
the same user can leave one comment or many comments to a topic/article... on the same page i will have different comments leave by other users which are approved by admin...
i would like to know what is the best way to handle?
example:
[some topic here.........................
...................................................]
*comments:*
abc ............................... [pendign approval] //this data will be coming from session
xxxxxxxxxxxxxx......................[approved] //all the approved coming from db
aaaaaaaaaaaaaaaaaa..................[approved]
............
..................
.................
Upvotes: 0
Views: 132
Reputation: 218732
I don't think you should depend session for this. You should probably store the comment status with a different status in the table.
Ex : When a comment is newly posted ,save it to the database with status as 0 / "Pending"
Wen Admin approves, change it to 1/"Approved"
If admin rejects , change it to -1/ "rejected" / delete the record if you dont want to store it any more
When the page loads (for all users/public), get the records filtered by status
SELECT ID,COMMENT FROM COMMENTS WHERE STATUS=1 AND POST_ID=@postId
When the page loads (for all a user who posted the comment), get the records filtered by status ( include pending also now)
SELECT ID,COMMENT FROM COMMENTS WHERE
((STATUS IN =1)
OR (STATUS =0 AND CREATED_BY=@currentUserId))
AND POST_ID=@postId
Upvotes: 2
Reputation: 12413
You will need to allocate anonymous users an account automatically (similar to the registered users ones). When a user registers you can upgrade their account. In this way the same process can be used to display comments from both.
Upvotes: 0