Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to build a commenting system on top of my existing posting system in PHP?
    primarykey
    data
    text
    <p>I have a page where the latest status updates by my friends and me are displayed.</p> <p>The tables involved are statusUpdates, users &amp; friends.</p> <p>The script I used to pull the necessary data was -</p> <pre><code>$myQuery = mysql_query("SELECT * FROM statusUpdates AS su LEFT JOIN friends AS fr ON fr.frContactID = su.authorID JOIN (users AS u) ON (u.roll = su.authorID) WHERE (fr.frHostID = ".$userLoggedIn['roll']." or su.authorID = ".$userLoggedIn['roll'].") GROUP BY su.statusID ORDER BY su.statusID DESC LIMIT 0,15"); </code></pre> <p>And I printed the data using this -</p> <pre><code>if (mysql_num_rows($myQuery) == 0) echo "No updates to show"; else { while ($row = mysql_fetch_assoc($myQuery)) { // Print $row['statusID'], $row['status'], $row['authorID'], $row['fullName'], $row['userProfileLink'], etc } } </code></pre> <p>Now I am also thinking of incorporating a commenting system. For that I will be creating a new table <strong>comments</strong> with the following fields - <code>commentID, targetStatusID, commentorID, comment, commentTimeStamp</code></p> <p>How should I adjust my mysql queries so that the comments for each status update also get printed out in the following way -</p> <pre><code>status1 - comment1 - comment2 - comment3 [text field for new comment to status1] status2 - comment1 [text field for new comment to status2] status3 [no comments for this post] [text field for new comment to status3] status4 - comment1 - comment2 [text field for new comment to status4] [no more posts to show] </code></pre> <p>Please note that -</p> <p><strong>commentID</strong> is the primary key. <strong>targetStatusID</strong> indicates the particular status update on which the comment was made. <strong>commentorID</strong> is the ID of the person who commented. <strong>comment</strong> is the actual content. <strong>commentTimeStamp</strong> shows the time when the comment was made.</p> <p>By the way, I would like to achieve the whole thing using procedural programming, and <em>not OOP</em>.</p> <p>One of the ways to solve this would be by using a query inside while <code>($row = mysql_fetch_assoc($myQuery))</code> to select comments for <code>$row['statusID']</code>.</p> <p>But that would build up the number of queries if I wanted to display many posts.</p> <p>So what should my approach be?</p> <p>P.S. I came across similar questions, but none of their answers solved my issue.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload