0

The problem is I think in function viewNews(), so I made that function to get the articles/news from database. Well, I tried to put function showCommentsArea() inside viewNews() function, but it shows me same comments in every article, I want like separated comments for every article, like on Facebook, I mean, when you enter someone's post (in this case article), you can publish a comment only for that post (article).

I tried putting showCommentsArea() function inside viewNews() function, right after displaying timestamp of that article.

# Function for viewing news. #
    function viewNews()
    {
      global $db;
      $query = "SELECT * FROM newsmodule ORDER BY timestamp";
      $result = @mysqli_query($db, $query);
      if (!$result)
      {
        echo "Error selecting headline from database.";
        exit();
      }
      if (mysqli_num_rows($result) > 0)
      {
        echo "<div style='margin-left: 0; width: 100%;' class='jumbotron'>";
        while ($row = mysqli_fetch_object($result))
        {
          echo "<h1><br>" . $row->headline . "</h1>";
          echo "<hr>";
          echo "<p>" . $row->storyline . "</p>";
          echo "<hr>";
          echo "<h5 class='pull-right'>" . $row->username . "</h5>";
          echo "<p>" . $row->timestamp . "</p>";
          echo "<hr>";
          echo showCommentArea();
          echo "<a data-target='#postComment' class='text-white dropdown-toggle btn btn-danger' data-toggle='modal' type='button'>";
          echo  "Publish a Comment";
          echo "</a>";
        }
        echo "</div>";
      }
      else
      {
        echo "No headlines in database.";
      }
    }
function showCommentArea()
    {
      global $db, $errors, $username;
      if(count($errors) == 0)
      {
        $query = "SELECT comment, name FROM comments
                  JOIN newsmodule ON comments.articlecID=newsmodule.id WHERE newsmodule.id=comments.articlecID";
        $result = @mysqli_query($db, $query);
        if(!$result)
        {
          echo "SQL Query ERROR: !ERR_SQL_QUERY_01";
          exit();
        }
        if (mysqli_num_rows($result) > 0) {
          echo "<div>";
          echo "<h4>";
          echo "Comments:";
          echo "</h4>";
          echo "<br>";
          while ($row = mysqli_fetch_object($result)) {
            echo "<p class='text-danger' style='font-weight: bold;'>" . $row->name . "</p>";
            echo "<p>" . $row->comment . "</p>";
          }
          echo "</div>";
        }
      }
    }

So, I expect to have one individual comments section for one individual post, you see I tried to add it with JOINING tables, but it shows me entire table 'comments'

ravenousHydra
  • 53
  • 2
  • 9

0 Answers0