I have two tables:
comment
id - unique comment id
topicid - the id of the topic being commented on
mid - member id
mname - membername
mgroup - membergroup
comment - the comment
date - the date in which the comment was posted (timestamp)
helpful
commentid - the id for the comment being rated
mid - memberid
mname - membername
mgroup - membergroup
helpful - was it helpful or not? (1 = yes, 0 = no)
Now what I have is the ability for members to post comments on a particular topic, whether it be a movie review or a simple article. Now this is fine and works perfectly as does the ability for members to rate whether the comment itself was helpful.
But what I want is to have only one comment displayed on the page with the topic itself. This comment is one of the following (in order of which comes first)
- The most helpful comment
- The last posted comment, when no comments have been rated
Now is there a way do to this?
Also note that the most helpful comment is not necessarily the comment with the most helpful votes. For example a comment that has 10 helpful votes and 10 not helpful votes is not more helpful than one with 9 helpful votes and 1 not helpful votes (ie one is 50% helpful whereas the other is 90%).
Any help on this issue would be greatly appreciated. In addition I would like to thank all those who offer a hand in advance for their time.