SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2001
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question concerning News + Comments script I want to create

    Hi, I'm about to create a news with comments script but I have a few questions.
    I've been reading the PHP/Mysql book by Kevin Yank concerning relational database design. So I would have to make 3 tables: NEWS, COMMENTS, NEWS_COMMENTS, am I right ?

    So, if I insert a NEWS entry, there should automatically be an ID equal to the NEWS one submitted to NEWS_COMMENTS which will be used to link with the COMMENTS right?

    Now, could anyone tell me how my code would have to look like?

    INSERT INTO NEWS etc..

    Also, let's say I wan't to submit news with PHPMyadmin, is there a way so an ID would be submitted to NEWS_COMMENTS ?

    Thnx in advance.

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    People might disagreee with me here, but I would just have two tables: news and comments. Then use the news id as a foreign key in comments:

    News:

    news_id
    date
    blah ...

    Comments:

    comment_id
    comment
    blah ...
    news_id

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    seanf's way sounds like the way to go. This is like a Slashdot type site where visitors can comment on news articles right?

    So just insert the news like normal, INSERT INTO news article = '$article'...

    And once it's on the site, person adds a comment, and you'll insert the comment to the db like

    INSERT INTO comment comment = '$comment', news_id = $news_id...

    You would get the $news_id from the URL, hidden field, etc.
    Work smarter, not harder. -Scrooge McDuck

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2001
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you explain it a little more plz, I can't quite follow

  5. #5
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You make two tables according to the structure mentioned by seanf.

    Person goes to news.php, and sees a bunch of news, each of those news has a news_id right?

    Person reads the news, and wants to comment on a news item, so he clicks on the "comment" link, which takes him to post_comment.php?news_id=234

    When the user arrives at that page, he types his comment, and submit. You would insert his comment to the database like

    INSERT INTO comments comment = '$comment", news_id = $news_id

    That comment is not associated with that picticular news item.

    If you want to view a list of comments that belongs to a pictiular news item, just go:

    SELECT * FROM comments WHERE news_id = $news_id
    Work smarter, not harder. -Scrooge McDuck

  6. #6
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Robo
    That comment is not associated with that picticular news item.
    Don't you mean:
    That comment IS associated with that particular news item. ?
    Oh no! the coots are eating my nodes!


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
  •