Efficient way to build a forum

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Trojanek

    Efficient way to build a forum

    Hi there.

    This is not really a PHP-question, but I think you guys should know that ;-)

    I am building a forum for a friend of mine using Borland Delphi's
    WebServices. It will be a rather small one, for just about ten people, older
    postings will be deleted after 3 months.

    From the Delphi-side, I know how to do it but I'm not sure about how to keep
    the hierachical structure when saving the threads. Right now, I would store
    each post (and therefore each reply) in a seperate .txt on the server, write
    it's ID and timestamp into and remember it's child-post(s) (if it has one).

    There has to be a better way. So could anyone tell me how this task is
    accomplished in PHP? Please don't post any PHP-source, I just want to know
    how it is usually done and I'll try to do that using Delphi.

    Thanks in advance

    Mike


  • kafooey

    #2
    Re: Efficient way to build a forum

    On Thu, 20 Nov 2003 09:33:33 +0100, "Michael Trojanek"
    <tro@adv.magwie n.gv.at> wrote:
    [color=blue]
    >I am building a forum for a friend of mine using Borland Delphi's
    >WebServices. It will be a rather small one, for just about ten people, older
    >postings will be deleted after 3 months.
    >
    >From the Delphi-side, I know how to do it but I'm not sure about how to keep
    >the hierachical structure when saving the threads. Right now, I would store
    >each post (and therefore each reply) in a seperate .txt on the server, write
    >it's ID and timestamp into and remember it's child-post(s) (if it has one).
    >
    >There has to be a better way. So could anyone tell me how this task is
    >accomplished in PHP? Please don't post any PHP-source, I just want to know
    >how it is usually done and I'll try to do that using Delphi.[/color]

    In PHP it's usually database driven.

    The easiest way is to have a topics table and a posts table. Each row
    in the posts table may point to a parent post, or to itself (if it's
    the root post), and the topics table is used to stage "last post",
    "num replies" etc to avoid overhead when listing topics.

    You would normally put the message bodies in a seperate table too.

    You can build on top of that of course with topic sections etc, but
    the above explains the basics.


    kafooey
    - kafooey@nospam. yahoo.co.uk
    - http://www.pluggedout.com/blog

    Comment

    • Nicolas

      #3
      Re: Efficient way to build a forum

      Each answer has the id of its parent.
      id = 0 for heads of threads (no parent).

      Recursive functions can find their ways in the messages tree very easily.

      Better use a database than flat files to store the messages.

      Nicolas



      Comment

      • Kevin Thorpe

        #4
        Re: Efficient way to build a forum

        Nicolas wrote:[color=blue]
        > Each answer has the id of its parent.
        > id = 0 for heads of threads (no parent).[/color]

        I would also include a thread id to select all related messages easily.
        [color=blue]
        > Recursive functions can find their ways in the messages tree very easily.
        >
        > Better use a database than flat files to store the messages.[/color]

        Definitely
        [color=blue]
        > Nicolas[/color]

        Comment

        • Nicolas

          #5
          Re: Efficient way to build a forum

          > I would also include a thread id to select all related messages easily.

          Right : I had to add it to my first forum because otherwise it was a real
          pain to get all messages from one thread.

          Nicolas


          Comment

          • Tim Van Wassenhove

            #6
            Re: Efficient way to build a forum

            On 2003-11-21, Nicolas <fausse@adresse .com> wrote:[color=blue][color=green]
            >> I would also include a thread id to select all related messages easily.[/color]
            >
            > Right : I had to add it to my first forum because otherwise it was a real
            > pain to get all messages from one thread.[/color]

            There is no need for that.

            The first message in a thread, gets parent_id=0

            Now selecting all the messages in this thread:

            function show_message($m essageid) {
            // show message
            select message_id from messages where parent_id=$mess ageid
            foreach(message _id) {
            show_message($m essage_id)
            }
            }

            --
            verum ipsum factum

            Comment

            • Kevin Thorpe

              #7
              Re: Efficient way to build a forum

              Tim Van Wassenhove wrote:[color=blue]
              > On 2003-11-21, Nicolas <fausse@adresse .com> wrote:
              >[color=green][color=darkred]
              >>>I would also include a thread id to select all related messages easily.[/color]
              >>
              >>Right : I had to add it to my first forum because otherwise it was a real
              >>pain to get all messages from one thread.[/color]
              >
              >
              > There is no need for that.
              >
              > The first message in a thread, gets parent_id=0
              >
              > Now selecting all the messages in this thread:
              >
              > function show_message($m essageid) {
              > // show message
              > select message_id from messages where parent_id=$mess ageid
              > foreach(message _id) {
              > show_message($m essage_id)
              > }
              > }[/color]

              If you are using a flat forum then this would be fine. If, however you
              are using a tiered indented forum then that will only give you replies
              to the original post. You would need a recursive routine to list replies
              to each reply. Lots and lots of SQL queries.


              Comment

              • Tim Van Wassenhove

                #8
                Re: Efficient way to build a forum

                On 2003-11-21, Kevin Thorpe <kevin@pricetra k.com> wrote:[color=blue]
                > Tim Van Wassenhove wrote:[color=green]
                >> On 2003-11-21, Nicolas <fausse@adresse .com> wrote:
                >>[color=darkred]
                >>>>I would also include a thread id to select all related messages easily.
                >>>
                >>>Right : I had to add it to my first forum because otherwise it was a real
                >>>pain to get all messages from one thread.[/color]
                >>
                >>
                >> There is no need for that.
                >>
                >> The first message in a thread, gets parent_id=0
                >>
                >> Now selecting all the messages in this thread:
                >>
                >> function show_message($m essageid) {
                >> // show message
                >> select message_id from messages where parent_id=$mess ageid
                >> foreach(message _id) {
                >> show_message($m essage_id)
                >> }
                >> }[/color]
                >
                > If you are using a flat forum then this would be fine. If, however you
                > are using a tiered indented forum then that will only give you replies
                > to the original post. You would need a recursive routine to list replies
                > to each reply. Lots and lots of SQL queries.[/color]

                Err, what am i missing? my pseudo function does have recursion.

                --
                verum ipsum factum

                Comment

                • Kevin Thorpe

                  #9
                  Re: Efficient way to build a forum

                  Tim Van Wassenhove wrote:[color=blue]
                  > On 2003-11-21, Kevin Thorpe <kevin@pricetra k.com> wrote:
                  >[color=green]
                  >>Tim Van Wassenhove wrote:
                  >>[color=darkred]
                  >>>On 2003-11-21, Nicolas <fausse@adresse .com> wrote:
                  >>>
                  >>>
                  >>>>>I would also include a thread id to select all related messages easily.
                  >>>>
                  >>>>Right : I had to add it to my first forum because otherwise it was a real
                  >>>>pain to get all messages from one thread.
                  >>>
                  >>>
                  >>>There is no need for that.
                  >>>
                  >>>The first message in a thread, gets parent_id=0
                  >>>
                  >>>Now selecting all the messages in this thread:
                  >>>
                  >>>function show_message($m essageid) {
                  >>> // show message
                  >>> select message_id from messages where parent_id=$mess ageid
                  >>> foreach(message _id) {
                  >>> show_message($m essage_id)
                  >>> }
                  >>>}[/color]
                  >>
                  >>If you are using a flat forum then this would be fine. If, however you
                  >>are using a tiered indented forum then that will only give you replies
                  >>to the original post. You would need a recursive routine to list replies
                  >>to each reply. Lots and lots of SQL queries.[/color]
                  >
                  >
                  > Err, what am i missing? my pseudo function does have recursion.
                  >[/color]
                  Ah, sorry... it is Friday afternoon here.

                  Doing that though does hit the SQL server a lot more than selecting all
                  messages for a thread.

                  Comment

                  • Nicolas

                    #10
                    Re: Efficient way to build a forum

                    > There is no need for that.

                    I agree you can do without, but is it better ?

                    It is always a problem when working with trees which are saved in databases
                    : put the load on the SQL server or on PHP (or on both). Sometimes it is not
                    a bad idea to deal with a subset of the tree with PHP rather than overload
                    the SQL server.

                    Nicolas


                    Comment

                    • Christian Debt Man

                      #11
                      Re: Efficient way to build a forum

                      Tim Van Wassenhove, obviously a huge fan of Bruce Campbell, wrote:[color=blue]
                      >
                      > function show_message($m essageid) {
                      > // show message
                      > select message_id from messages where parent_id=$mess ageid
                      > foreach(message _id) {
                      > show_message($m essage_id)
                      > }
                      > }[/color]

                      Jesus christ, I'm glad I'm not sharing an sql server with you.

                      /joe
                      --
                      Jeff Jones's load of ducketts is terrific.

                      Comment

                      • Default User

                        #12
                        Re: Efficient way to build a forum

                        Kevin Thorpe wrote:
                        [color=blue][color=green][color=darkred]
                        > >>If you are using a flat forum then this would be fine. If, however you
                        > >>are using a tiered indented forum then that will only give you replies
                        > >>to the original post. You would need a recursive routine to list replies
                        > >>to each reply. Lots and lots of SQL queries.[/color]
                        > >
                        > >
                        > > Err, what am i missing? my pseudo function does have recursion.
                        > >[/color]
                        > Ah, sorry... it is Friday afternoon here.
                        >
                        > Doing that though does hit the SQL server a lot more than selecting all
                        > messages for a thread.[/color]


                        You can do both things. Have a thread ID, and have a reference, that
                        being the message ID of the message it replies to. Use the thread ID to
                        pull all the messages from the database in one query, putting then in an
                        array or something. Then use the references and timestamps to sort into
                        a tree structure.



                        Brian Rodenborn

                        Comment

                        Working...