www.webdeveloper.com
Results 1 to 3 of 3

Thread: Help: adding commenting functionality to news articles

  1. #1
    Join Date
    Jul 2008
    Posts
    92

    Help: adding commenting functionality to news articles

    What's the common method for creating news articles which allow readers to post comments on those articles? I'm still learning web dev, but I have set up a clan site for me and my friends here http://mith-project.net

    If you visit it, youll see I have news announcements both in the header and on the front page. I would absolutely love it if I could allow readers to post comments on the announcements. Also, I'd like to post each of my php/sql stories into the forum (a phpbb3 forum--are there any better ones around?) where the comments would be paralleled to the comments on the front page.

    I just need some help understanding the php/sql structure that is required to allow cross posting with a single user account between two different sql databases, if it is even possible.

    If it isn't could someone just explain how to the news story comments work out? If you dont know what I mean, check almost any popular site, such as slashdot, where readers can post comments on each article.

    Thanks.

  2. #2
    Join Date
    Apr 2007
    Posts
    1,664
    just to let you know the site is incredibly slow opening for me right now. Maybe 30 seconds load time.

    To answer your question briefly. I presume your news is stored in a database table and that table has an auto increment id so each news item has a unique identity (called something like newsid). If you make another table you can store any comments and the newsid (Unix time stamp too for time/date and the userid).

    When you display the news article you have the id of the article to display so you also look in the comments table for any comments with the same news id and display them too (ordered by the timestamp).

    Add a form to the article page and store the comments with the relevant newsid.

    You join tables together with numerical ids ( and indexed columns for speed) and organise your structure around those ids.

    so user id 123 has an comment on newsarticle id 789.

    The page has an address like
    news.php?newsid=789

    news table has
    Code:
    newsid		title		content
    789		clan stuff	Lots of stuff

    comments table has
    Code:
    commentid	newsid	userid	comment
    1		789	123	Yeaaa, clan stuff!
    user table has
    Code:
    userid	name
    123	bob
    So from the newsid in the URL I can get the article content with a simple
    Code:
    select * from news where newsid=789
    I can get the comments too with a similar select
    Code:
    select * from comments where newsid=789
    from this I can return the userid and et the users info.

    Once you get this very basic way of doing it working you have to consider a few more things.

    The security of the statements and sanitizing all user inputs and URL string input.
    Sanitize your input (google for it) or I could simply change the url to
    Code:
    news.php?newsid=789';drop table users
    and you table data is gone!!

    Next for efficiency, joining tables together to do it all in a single SQL statement.

  3. #3
    Join Date
    Jul 2008
    Posts
    92
    Thank you very much! I know the site was slow earlier. Not sure what was up with it, but I think it's fixed now. I'm going to spend some time trying this out and I'll get back with how it goes.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles