Web Analytics Made Easy -
StatCounter Displaying replies - CodingForum

Announcement

Collapse
No announcement yet.

Displaying replies

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Displaying replies

    Hello, i've a forum and i want it to display the topic and it's replies on one page. http://www.roelt.nl/phpengine/Freakz/ i made it display a replie but it displays only the newest. And i want it to display all the replies with the newest on the bottom of the page.
    Here is my code:
    PHP Code:
    <?php 
       
    /* Maak connection */ 
       
    $db mysql_connect("localhost""username""password"); 
       
    mysql_select_db("database"); 
        
       
    /* Read the message */ 
       
    $sql "SELECT id, naam, titel, inhoud FROM forum WHERE id='$id'"
       
    $result mysql_query($sql) or die(mysql_error()); 
       if (
    mysql_num_rows($result) == 0) { 
          echo 
    "<p>\n"
       } 
       else {   
    // Schrijf alle berichten 
          
    $row mysql_fetch_object($result); 
          echo 
    "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"600\">\n"
          echo 
    "<tr style=\"background-color: #999999; color: White; font-weight: Bold;\">\n"
          echo 
    "\t<td width=\"20%\">Title</td>\n"
          echo 
    "\t<td width=\"80%\">$row->titel</td>\n"
          echo 
    "</tr>\n<tr>\n"
          echo 
    "<td>Name:</td>\n"
          echo 
    "<td>$row->naam</td>\n"
          echo 
    "</tr>\n<tr>\n"
          echo 
    "<td>Content:</td>\n"
          echo 
    "<td>$row->inhoud</td>\n"
          echo 
    "</tr>\n"
          echo 
    "</table><p>\n"
          echo 
    "<a href='bericht.php?replyto=$id'>Reply</a>"
       } 
    ?> 
    <?php 
       
    /* Maak connection */ 
       
    $db mysql_connect("localhost""user""pass"); 
       
    mysql_select_db("db"); 
        
       
    /* Read the message */ 
       
    $sql "SELECT id, naam, titel, replyto, inhoud FROM forum WHERE replyto='$id'"
       
    $result mysql_query($sql) or die(mysql_error()); 
       if (
    mysql_num_rows($result) == 0) { 
          echo 
    "Oops... this post doesn't exist ;(<p>\n"
       } 
       else {   
    // Write messages 
          
    $row mysql_fetch_object($result); 
          echo 
    "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"600\">\n"
          echo 
    "<tr style=\"background-color: #999999; color: White; font-weight: Bold;\">\n"
          echo 
    "\t<td width=\"20%\">Title</td>\n"
          echo 
    "\t<td width=\"80%\">$row->titel</td>\n"
          echo 
    "</tr>\n<tr>\n"
          echo 
    "<td>Name:</td>\n"
          echo 
    "<td>$row->naam</td>\n"
          echo 
    "</tr>\n<tr>\n"
          echo 
    "<td>Content:</td>\n"
          echo 
    "<td>$row->inhoud</td>\n"
          echo 
    "</tr>\n"
          echo 
    "</table><p>\n"
          echo 
    "<a href='bericht.php?replyto=$id'>Reply</a>"
       } 
    ?>
    Last edited by MPCODER; Feb 7, 2004, 11:22 AM.

  • #2
    It's a PHP issue. You have this
    PHP Code:
    else { 
         
    $row mysql_fetch_object($result); 
          echo 
    "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"600\">\n"
          echo 
    "<tr style=\"background-color: #999999; color: White; font-weight: Bold;\">\n"
          echo 
    "\t<td width=\"20%\">Title</td>\n"
          echo 
    "\t<td width=\"80%\">$row->titel</td>\n"
          echo 
    "</tr>\n<tr>\n"
          echo 
    "<td>Name:</td>\n"
          echo 
    "<td>$row->naam</td>\n"
          echo 
    "</tr>\n<tr>\n"
          echo 
    "<td>Content:</td>\n"
          echo 
    "<td>$row->inhoud</td>\n"
          echo 
    "</tr>\n"
          echo 
    "</table><p>\n"
          echo 
    "<a href='bericht.php?replyto=$id'>Reply</a>"

    Which will print the value from the record where the pointer is at when the recordset is retrieved (first record)

    You need to loop through the recordset to have the code execued for all records. Like


    PHP Code:
    else { 
       while (
    $row mysql_fetch_object($result)){ 
          echo 
    "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"600\">\n"
          echo 
    "<tr style=\"background-color: #999999; color: White; font-weight: Bold;\">\n"
          echo 
    "\t<td width=\"20%\">Title</td>\n"
          echo 
    "\t<td width=\"80%\">$row->titel</td>\n"
          echo 
    "</tr>\n<tr>\n"
          echo 
    "<td>Name:</td>\n"
          echo 
    "<td>$row->naam</td>\n"
          echo 
    "</tr>\n<tr>\n"
          echo 
    "<td>Content:</td>\n"
          echo 
    "<td>$row->inhoud</td>\n"
          echo 
    "</tr>\n"
          echo 
    "</table><p>\n"
          echo 
    "<a href='bericht.php?replyto=$id'>Reply</a>";
       } 
    // closes the while loop
    // closes the else-clause 
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      It gives a parse error with your solution. Please post the entire code i should use.

      Comment


      • #4
        I fixed the issue with the newest post above. But still it display's only one replie. Please help me with this.
        Cheers MPCODER

        Comment


        • #5
          Originally posted by MPCODER
          It gives a parse error with your solution. Please post the entire code i should use.
          That is the entire code. You just nee to add a loop around it with the while-construct.
          Post the line that the parse-error points to. But i would surprise me if it is on the one line i edited from your code
          I fixed the issue with the newest post above. But still it display's only one replie. Please help me with this.
          Do you mean the code in your original post? I still don't see the while loop inthere ...
          Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

          Comment


          • #6
            Where should i put the code? in the first section or in the second?

            Comment


            • #7
              The second.

              But the problem is probaly your db-design. Because both for rhe messages as for the replys, you select on forum. Do you create a new record (line) in this table for each reply ?

              You'd norùmally have a table for each 'thread' and then another table for each reply (where you store the primary-key value of the thread to make a join to the threads-table.

              You also don't need the second select...
              PHP Code:
              <?php 
                 
              /* Maak connection */ 
                 
              $db mysql_connect("localhost""username""password"); 
                 
              mysql_select_db("database"); 
                  
                 
              /* Read the message */ 
                 
              $sql "SELECT id, naam, titel, inhoud FROM forum WHERE id='$id'"
                 
              $result mysql_query($sql) or die(mysql_error()); 
                 if (
              mysql_num_rows($result) == 0) { 
                    echo 
              "<p>\n"
                 } 
                 else {   
              // Schrijf alle berichten 
                    
              $row mysql_fetch_object($result); 
                    echo 
              "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"600\">\n"
                    echo 
              "<tr style=\"background-color: #999999; color: White; font-weight: Bold;\">\n"
                    echo 
              "\t<td width=\"20%\">Title</td>\n"
                    echo 
              "\t<td width=\"80%\">$row->titel</td>\n"
                    echo 
              "</tr>\n<tr>\n"
                    echo 
              "<td>Name:</td>\n"
                    echo 
              "<td>$row->naam</td>\n"
                    echo 
              "</tr>\n<tr>\n"
                    echo 
              "<td>Content:</td>\n"
                    echo 
              "<td>$row->inhoud</td>\n"
                    echo 
              "</tr>\n"
                    echo 
              "</table><p>\n"
                    echo 
              "<a href='bericht.php?replyto=$id'>Reply</a>"
                 } 
              ?> 
              <?php //
              // Waar is deze tweede db-connect voor nodig? Er is al een actieve connectie uit het eerste stuk code 
                 /* Maak connection */ 
                 
              $db mysql_connect("localhost""user""pass"); 
                 
              mysql_select_db("db"); 
                  
                 
              /* Read the message */ 
                 
              $sql "SELECT id, naam, titel, replyto, inhoud FROM forum WHERE replyto='$id'"
                 
              $result mysql_query($sql) or die(mysql_error()); 
                 if (
              mysql_num_rows($result) == 0) { 
                    echo 
              "Oops... this post doesn't exist ;(<p>\n"
                 } 
                 else {   
              // Write messages 
                   
              while ($row mysql_fetch_object($result)){ 
                     echo 
              "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"600\">\n"
                     echo 
              "<tr style=\"background-color: #999999; color: White; font-weight: Bold;\">\n"
                     echo 
              "\t<td width=\"20%\">Title</td>\n"
                     echo 
              "\t<td width=\"80%\">$row->titel</td>\n"
                     echo 
              "</tr>\n<tr>\n"
                     echo 
              "<td>Name:</td>\n"
                     echo 
              "<td>$row->naam</td>\n"
                     echo 
              "</tr>\n<tr>\n"
                     echo 
              "<td>Content:</td>\n"
                     echo 
              "<td>$row->inhoud</td>\n"
                     echo 
              "</tr>\n"
                     echo 
              "</table><p>\n"
                     echo 
              "<a href='bericht.php?replyto=$id'>Reply</a>";
                   } 
                 } 
              ?>
              Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

              Comment

              Working...
              X