Results 1 to 8 of 8

Thread: State article with its comments

  1. #1
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default State article with its comments

    I have 2 tables one for articles and the other for comments

    how can I fetch the comments of each article

    now when I made fectching all comments show in the first article

    I need to state every article with it's comments

    plz I need code example also

  2. #2
    Join Date
    Oct 2008
    Location
    London, UK
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Within your articles table, make sure each one has a unique id. Then in your comments table make sure you have an article id field.
    Every time a comment is submitted into the comments table make sure it is inserted with the article id field that is necessary to it.

    Then on the PHP side of things. To display all the relevant comments for each article, at the bottom of the article's page have something like:

    PHP Code:
    <?php
    $query 
    mysql_query("SELECT * FROM comments WHERE `articleid` = '$tutid'");


    while(
    $row mysql_fetch_array($query)){
        echo 
    $row['commentitle'] . "<br />" $row['commentauthor'] . "<br />" $row['comment'];
        }
    ?>

  3. #3
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oooh I got the trick

    I am trying it now

    plz keep in touch to give you the result

  4. #4
    Join Date
    Oct 2008
    Location
    London, UK
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No problem, just ask here again if you need anything else.

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Benji, shouldn't you escape the string?
    Jeremy | jfein.net

  6. #6
    Join Date
    Oct 2008
    Location
    London, UK
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yeah, you definitely should - I was just typing up a basic example of how to while loop out data from a database table.

    It's also worth doing htmlentities sometimes for extra security against malicious code injections.

  7. #7
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Ok. I see.
    Jeremy | jfein.net

  8. #8
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hi BBarash

    everything is ok
    my funny script work very good specially comments.

    thx again and again

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
  •