tutorials on this?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan
    Senior Member
    • Mar 2004
    • 1229

    #1

    tutorials on this?

    Anybody know of **simple** tutorials on how
    to build scripts that use parental/children IDs?

    I want an actual tutorial, as my PHP book has
    a chapter purely dedicated to build a forums system,
    yet I do not understand much of how it works

    Basicly I want to use it for several reason:

    1) Links directory, matching certain links
    only to the "category ID" that matchs the 'parent ID'

    2) News Script with comments, matching comments
    only to the news article ID that matchs the 'parent ID'

    3) Pre-lude for an *extremely* simple forums possibly?
    "How can someone be so distracted yet so focused?"
    - C
  • Buddha
    Senior Member
    • Mar 2004
    • 825

    #2
    For an extremely simple forum, you may not need a very complicated parent/child relationship, as in no threaded discussions.

    Code:
    TABLE thread
    thread_id # parent
    thread_title
    thread_author
    thread_published
    thread_text
    
    TABLE comment
    comment_id # child
    thread_id
    comment_title
    comment_author
    comment_published
    comment_text
    To display a list of topics is simple:

    Code:
    SELECT thread_id, thread_title, thread_author, thread_published 
    FROM thread
    ORDER BY thread_published DESC
    LIMIT 0, 5
    To display a topic isn't much harder:

    Code:
    # GET THE TOPIC
    SELECT * FROM thread
    WHERE thread_id = '$id'
    LIMIT 1
    
    # GET THE COMMENTS
    SELECT *
    FROM comment
    WHERE thread_id = '$id'
    ORDER BY comment_published ASC
    LIMIT 0, 5
    Here I used two tables for clarity but you could do it with just one. As you can see the fields over lap.
    "Whatcha mean I shouldn't be rude to my clients?! If you want polite then there will be a substantial fee increase." - Buddha

    Comment

    • Jonathan
      Senior Member
      • Mar 2004
      • 1229

      #3
      Awsome Buddha; that confirms what I was trying to do,
      but it didn't seem to work on my computer (uploaded and worked fine);

      Basicly, I want to set a links directory, where only show
      links if the 'cat_id' matchs the 'id', and if not show an generic message
      "How can someone be so distracted yet so focused?"
      - C

      Comment

      • Buddha
        Senior Member
        • Mar 2004
        • 825

        #4
        Originally posted by Jonathan
        Awsome Buddha; that confirms what I was trying to do,
        but it didn't seem to work on my computer (uploaded and worked fine);
        Hope you didn't try to run that it was just pseudocode.

        Basicly, I want to set a links directory, where only show
        links if the 'cat_id' matchs the 'id', and if not show an generic message
        I wasn't sure what you meant by that the first time and I'm still not sure either? It sounds like you want a collections of links that are associated with a catagory.

        Code:
        TABLE link
        link_id
        link_url
        link_title
        link_alt_text
        catagory_id
        
        TABLE catagory
        catagory_id
        catagory_name
        Code:
        SELECT t1.link_url, t1link_title, t1link_alt_text, t2.catagory_name
        FROM link AS t1, catagory AS t2 
        WHERE catagory_id = $id
        AND t1.catagory_id = t2.catagory_id
        Of course you'll have to make that JOIN work in whatever database your using.

        To figure out what to display just see how many rows were returned.
        Code:
        IF ( num_rows( $result ) > 0 ) THEN
            DISPLAY_RESULTS();
        ELSE
            DISPLAY_DEFAULT_MESSAGE();
        ENDIF
        "Whatcha mean I shouldn't be rude to my clients?! If you want polite then there will be a substantial fee increase." - Buddha

        Comment

        Working...