SitePoint Sponsor

User Tag List

Results 1 to 22 of 22

Thread: Display Post #

  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Display Post #

    I just added the ability to Comment on Articles on my website, and would like to place "Post #___" in the upper right-hand corner of each Comment.

    What is the best way to do that?

    It would seem to me that for a given Article, I want to somehow loop through all of the Comments and display an incremented #.

    Or do I do something in the Query that originally displays my Comments?


    Debbie

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Another possibility is adding a column to your table, and store the number there. That way, if you remove a comment, the other comments maintain their number.
    For example, there are 5 comments. I post the 6th, saying "I don't agree with comment #4 because...). Then you for some reason remove comment #3. That means comment #4 becomes #3, and #5 becomes #4, and my comment about comment #4 makes no sense anymore.

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Another possibility is adding a column to your table, and store the number there. That way, if you remove a comment, the other comments maintain their number.
    For example, there are 5 comments. I post the 6th, saying "I don't agree with comment #4 because...). Then you for some reason remove comment #3. That means comment #4 becomes #3, and #5 becomes #4, and my comment about comment #4 makes no sense anymore.
    Wow! You make a good point!!

    I just added a variable before my loop and then incremented the counter as I loop through and display each Comment.

    That seems to work well enough, but your point is making me re-think this.

    Anyone else?


    Debbie

  4. #4
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Hi Debbie,

    I fully agree with guido2004, By allowing the Comments that exist in the database to retain their id then bookmarking the comment is less likely to break in the future.

    Regards,
    Steve
    ictus==""

  5. #5
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    Hi Debbie,

    I fully agree with guido2004, By allowing the Comments that exist in the database to retain their id then bookmarking the comment is less likely to break in the future.

    Regards,
    Steve
    What does SitePoint do? (I suppose they never delete Posts.)

    So back to Guido's suggestion, when someone adds a new Comment, I would just find the maximum "Post #", increment by 1, and then store that in a field called "post_no"? Is that what you two are proposing?


    Debbie

  6. #6
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,290
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    What does SitePoint do? (I suppose they never delete Posts.)
    If appropriate we do . What vB (the forum software SPF uses) does is stores a unique id for each post, which is used in quoting so that the posts are always related to each other, but displays a "relative" post number on each post (the # in the top right of each post) which is counted by the page.

    Quote Originally Posted by DoubleDee View Post
    So back to Guido's suggestion, when someone adds a new Comment, I would just find the maximum "Post #", increment by 1, and then store that in a field called "post_no"? Is that what you two are proposing?
    Don't ever do that - if you're going to use a number, then use the autonumber functionality inherent to the database you're using. If you do a post count and increment, you run into the possibility that two people could post at the same instant, and end up with a duplicate (or a fatal error). Letting the dbms handle that resolves that problem.

    As for how to display them - do you want to display chronologically (that word sucks to spell - ackward for some reason), or do you want a threaded view?

    If you want chronologically, then you do a relative count from the first displayed.

    Post 1: 1/1/2012
    Post 2: 1/2/2012 <- delete this one
    Post 3: 1/3/2012
    Post 4: 1/4/2012

    becomes:

    Post 1: 1/1/2012
    Post 2: 1/3/2012
    Post 3: 1/4/2012

    If you want threaded, then you don't need a post number at all:

    Code:
    Post: 1/1/2012
         Post: 1/3/2012
    Post: 1/2/2012 <-- delete this post.
         Post: 1/5/2012
    Post: 1/4/2012
       Post: 1/4/2012
          Post: 1/5/2012
         Post: 1/5/2012
    becomes (since you should lose the post's reply as well..)

    Code:
    Post: 1/1/2012
         Post: 1/3/2012
    Post: 1/4/2012
       Post: 1/4/2012
          Post: 1/5/2012
         Post: 1/5/2012
    Last edited by DaveMaxwell; Mar 13, 2012 at 11:12. Reason: lost formatting....grrrrrrr
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  7. #7
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Dave,

    I am allowing members to post a Comment after one of my Articles. I am not allowing multi-level threads at this point. Everything is just a long list of Comments, based on "Post Date".

    You sort of lost me in your response...

    Yes, I do use an AutoIncrement ID for each Comment.

    But to ServerStorm's point, if I ever did delete a Comment, then since I am just using code at the "Presentation Level" to assign "Post #'s", the number would get messed up.

    If I deleted Coment #3, then this...
    1
    2
    3
    4

    ...would become this...
    1
    2
    3

    Where Comment #4 is now displayed as Comment #3

    It would look awkward to display the "commentID" since that could be gigantic.

    I see your point about not wanting to store Comment #'s/Order in the database, but to ServerStorm and Guido's point, you DO need to lock in the Original Comment # because if others say, "I disagree with what Dave said in Comment #4" then that needs to remain constant?!

    Sorry if I am not understanding your response.


    Debbie

  8. #8
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Hi Debbie,

    DaveMaxwell brings up a good point. Even the way your doing it the 'same time' post could occur (I've seen this in my own PHP apps) and throw an error an even (if it happens just right) corrupt the db. I don't want to speculate, but at this stage of your site/db design it may not be too difficult to add an auto-number column in your comments table and then it becomes a non-issue when things are deleted and you don't get the repeat (small) overhead to recalculate the post numbers; if your site ever gets big this will matter.

    My comment earlier is based on the fact that I often bookmark something that looks like this http://www.somedomain.com?id=1346792&comment=3

    if comment 2 was ever deleted then if comment 3 was the last comment then I'd get a 404 otherwise I would get what used to be comment 4, just not the information I saved.
    ictus==""

  9. #9
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    My comment earlier is based on the fact that I often bookmark something that looks like this http://www.somedomain.com?id=1346792&comment=3

    if comment 2 was ever deleted then if comment 3 was the last comment then I'd get a 404 otherwise I would get what used to be comment 4, just not the information I saved.
    Yes, I remembered the SP forums working like that too, but apparently I was wrong (or things have changed).
    Quote Originally Posted by DoubleDee View Post
    but to ServerStorm and Guido's point, you DO need to lock in the Original Comment # because if others say, "I disagree with what Dave said in Comment #4" then that needs to remain constant?!
    I was convinced that the SP forums worked that way, but I was wrong. So I won't say things like "I disagree with what Dave said in Comment #4" in my posts anymore.
    The problem is, as Dave pointed out, that you can't prevend problems from happening in case of simultaneous posting, because you can have only one autoincremental column in a table, and that column will be the comment id.
    I just added a variable before my loop and then incremented the counter as I loop through and display each Comment.
    I'd say you have found the right solution.

  10. #10
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,290
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    I see your point about not wanting to store Comment #'s/Order in the database, but to ServerStorm and Guido's point, you DO need to lock in the Original Comment # because if others say, "I disagree with what Dave said in Comment #4" then that needs to remain constant?!
    Sorry, but I disagree with your premise here - to lock in some sort of arbitrary number just to allow someone to comment like that is clumsy, IMO. Even SP doesn't try to do that (and there are those that reference back to "post #" in their quotes, though more just use the reply with quote button). A better option would be a mechanism which does a quote of the post/comment. This allows the user to reply to a specific point without having the developer having to worry about trying to keep posts together.

    As for your worry about the numbering - what you listed is correct. If post#3 is deleted, then post #4 becomes #3 and so on. The only issue would be the one you listed where someone could refer to a post no longer there, but unless you're going to be overzealous and delete all comments you don't like instead of the spammish ones, then there's nothing really to worry about....
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  11. #11
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Yes, I remembered the SP forums working like that too, but apparently I was wrong (or things have changed).
    I just checked a number of older SP forum comments bookmarks and they no longer work, but I do know that they used to do this. When these bookmarks were fresh, I used them somewhat regularly.

    Dave, maybe correct me if I am wrong, but I don't see a problem with having an auto-numbering column that keep tracks of comments. One could have a post table with auto-number post_id, and a comments table with auto-number comment_id and a comments2post mapping table that matches post_id with x number of comments.

    If a comment is deleted then the post no longer references it - no problem. The remaining comments still have there same ids and so any links to the comments are retained. Then if people want to book mark them, then go for it.

    Steve
    ictus==""

  12. #12
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DaveMaxwell View Post
    Sorry, but I disagree with your premise here - to lock in some sort of arbitrary number just to allow someone to comment like that is clumsy, IMO. Even SP doesn't try to do that (and there are those that reference back to "post #" in their quotes, though more just use the reply with quote button). A better option would be a mechanism which does a quote of the post/comment. This allows the user to reply to a specific point without having the developer having to worry about trying to keep posts together.
    Valid point.

    Guess I'll have to try and learn how to add a Quote feature to my Comments section.


    As for your worry about the numbering - what you listed is correct. If post#3 is deleted, then post #4 becomes #3 and so on. The only issue would be the one you listed where someone could refer to a post no longer there, but unless you're going to be overzealous and delete all comments you don't like instead of the spammish ones, then there's nothing really to worry about....
    Well, for now I have to approve all Comments before they are posted, so that would solve most of these issues.

    Thanks,


    Debbie

  13. #13
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    I just checked a number of older SP forum comments bookmarks and they no longer work, but I do know that they used to do this. When these bookmarks were fresh, I used them somewhat regularly.
    Well, this is a whole other topic unto itself.

    I think I have been bad on this topic in that I only use Sessions and Post to pass data. Although, I've never had issues Bookmarking things.


    Dave, maybe correct me if I am wrong, but I don't see a problem with having an auto-numbering column that keep tracks of comments. One could have a post table with auto-number post_id, and a comments table with auto-number comment_id and a comments2post mapping table that matches post_id with x number of comments.
    Not sure what you are calling a "Post" and "Comment"? To me they are the same.

    I could do a modification of that and have my "commentID" stay an auto number and then have a corresponding "viewableCommentID" that starts at one so even though it would stay sequential, it it better to have...

    1
    2
    3
    5
    7
    8

    versus

    3097
    3098
    3101
    3104
    3105

    and so on...


    If a comment is deleted then the post no longer references it - no problem. The remaining comments still have there same ids and so any links to the comments are retained. Then if people want to book mark them, then go for it.

    Steve
    I'm not following your Bookmarking thing...

    All of the Comments would be below an Article with no threading offered. So a Bookmark to "How Postage Meters Can Save You Money" should be unaffected by how the Comments are handled, right?!


    Debbie

  14. #14
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,290
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    Dave, maybe correct me if I am wrong, but I don't see a problem with having an auto-numbering column that keep tracks of comments. One could have a post table with auto-number post_id, and a comments table with auto-number comment_id and a comments2post mapping table that matches post_id with x number of comments.
    You are correct, and perhaps that's where I confused DD. If you look at the post indicators here (#11, #12, etc), you'll see that there is a link which goes to that specific post based on the postID, even though it displays as a relative number. This serves the human readable purpose of knowing where a comment/post is in a conversation, with the stability of being able to ties posts together as need be, as the id for a post should never change, though the relative number could change if a post earlier in the thread is deleted/moved.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  15. #15
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,290
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    Not sure what you are calling a "Post" and "Comment"? To me they are the same.

    I could do a modification of that and have my "commentID" stay an auto number and then have a corresponding "viewableCommentID" that starts at one so even though it would stay sequential, it it better to have...
    You're overthinking things and making them too complex - see my previous post where I tried to explain it better. There's a difference between a permanent indentifier and a relative identifier. A permanent identifier is used so that a record can always be found, regardless of what happens to it (it's moved, re-ordered, etc). A relative identifier is a human-readable indicator which will make sense to the user when they view it - i.e. the #12, #13 displayed in the top right corner of each post here....
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  16. #16
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Hi Debbie,

    I am thinking this:

    Posts Table (Simplified)
    id post
    1 I think that the problem is ...
    2 I like Kites, what do you ...

    Comments Table (Simplified)
    id comment
    1 The problem is not what you think...
    2 I also like Kites, in particular...
    3 No I agree with your view of the...
    4 What the F@ck you DINK!!!!
    5 I build my own kites see my blog ...
    6 Wow that is a big problem ...

    Comments2Posts (Simplified)
    comment_id post_id
    1 1
    2 2
    3 1
    4 1
    5 2
    6 1

    Then this will get all your comments related to each post
    Code:
    SELECT
       c2p.post_id
       ,c2p.comment_id
       , c.comment
    FROM
      comments as c
    INNER JOIN comments2posts as c2p
      ON c2p.comment_id = c.id
    Order By 
      post_id, comment_id
    Code:
    SELECT
      id
      , post
    FROM 
      posts
    Order By 
      id;
    Then:
    1. loop through these comments and put the post_id, comment_id, and comments into an array. After doing this you would have an array or comments arrays
    2. create a loop to read your posts. Inside this loop you first output the post (or put it into an $html variable) and then loop through comments and where comment's post_id = the post's id you then output this comment (or append it to your $html variable).
    By linking your comments this way you don't have to worry about re-ordering or if you implement a way where a user can bookmark an individual comment (like SP currently lets us bookmark a single post by selecting the post id and then bookmarking).

    Hope this helps.

    Steve
    ictus==""

  17. #17
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ServerStorm,

    I'm not following your terms...

    A "Thread" is this entire discussion (e.g. "Display Post #")

    A "Post" is each individual message (e.g. What I am typing now) related to the "Thread"


    In my world...

    I have an "Article". You can figure that out?!

    Then Users can make "Comments" to that "Article"

    So in my situation, there is no concept of a "Thread", although an "Article" is conceptual the same.

    A "Comment" is identical to a "Post".


    Sorry, but your (non-standard" use of the term "Post" got me really confused...

    Thanks,


    Debbie

  18. #18
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    ServerStorm,

    I'm not following your terms...

    A "Thread" is this entire discussion (e.g. "Display Post #")

    A "Post" is each individual message (e.g. What I am typing now) related to the "Thread"


    In my world...

    I have an "Article". You can figure that out?!

    Then Users can make "Comments" to that "Article"

    So in my situation, there is no concept of a "Thread", although an "Article" is conceptual the same.

    A "Comment" is identical to a "Post".


    Sorry, but your (non-standard" use of the term "Post" got me really confused...

    Thanks,


    Debbie
    Hi,

    So my 'Post' is your 'Article' and my 'Comment' is your 'Post', so the example i gave, the posts table would become the articles , the comment table would become posts, and the comments2posts table would become articles2posts. All the other logic would apply the same way.

    I whipped this together and read your posts too quickly, so sorry about the confusion.

    Steve
    ictus==""

  19. #19
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DaveMaxwell View Post
    You are correct, and perhaps that's where I confused DD. If you look at the post indicators here (#11, #12, etc), you'll see that there is a link which goes to that specific post based on the postID, even though it displays as a relative number. This serves the human readable purpose of knowing where a comment/post is in a conversation, with the stability of being able to ties posts together as need be, as the id for a post should never change, though the relative number could change if a post earlier in the thread is deleted/moved.
    No one is hearing me...

    I am responding to the Post Label #14 which is presumably relative, and postID=5083870 which is absolute and presumably the primary key for your Post.

    postID never changes.

    But if Post Label is just a calculated, relative number 1, 2, 3, 4,... then if an Admin deleted Post Label #13, then your Post #14 becomes Post Label #13 which is a problem if I am referring to it here.

    It would look silly to have the Post Label = postID = 5083870 although you could do that.

    Because we all agree that postID needs to remain a primary key...

    In the context of this Forum...

    I could use an AutoIncrement field called "Post Label" which is assigned "1" for each new "Thread", and then "Posts" would go 1, 2, 3, 4,... If a Post was deleted, the natural, physical ordering would remain, but there would be gaps like 1, 2, 4,... but at least the numbers would be READABLE!!!

    In the context of my website...

    I could use an AutoIncrement field called "Post Label" which is assigned "1" for each new "Article", and then "Posts" would go 1, 2, 3, 4,... If a Post was deleted, the natural, physical ordering would remain, but there would be gaps like 1, 2, 4,... but at least the numbers would be READABLE!!!


    In summary, that way you have a unique, primary key describing the Post that the database can use (e.g. 5083870) and you also have a unique key describing the Post that is more user-friendly (e.g. 1, 2, 3, 4, __, 6, 7, __, 9, 10,...)


    Debbie

  20. #20
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    Hi,

    So my 'Post' is your 'Article' and my 'Comment' is your 'Post', so the example i gave above will work the same way if you switch to your structure. Sorry about that... whipped it together quickly.

    Steve
    Steve,

    You are a *beautiful* person, but it is very UNCOOL to not use the terms "Thread" and "Post" properly on a website that consists almost entirely of "Threads" and "Posts"?! Grrr...


    Debbie

  21. #21
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    Steve,

    You are a *beautiful* person, but it is very UNCOOL to not use the terms "Thread" and "Post" properly on a website that consists almost entirely of "Threads" and "Posts"?! Grrr... Debbie
    Agreed (at least with the UNCOOL - maybe not very UNCOOL (a little harsh ) ), see my revised post above where I attempt to correct this. Conceptually this stays the same, but I do understand your point.

    Your post 19 shows you are on the right track. In my examples I was trying to show how you can use a mapping table to link your Posts to Articles. It then makes it relatively easy to display and group Articles with Posts in each Thread.

    Regards,
    Steve
    ictus==""

  22. #22
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    Agreed (at least with the UNCOOL - maybe not very UNCOOL (a little harsh
    Ha ha. Anyone else I would have let have it, but you're such a sweetie I'll let it slide this time...


    Debbie


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •