How to build a commenting system on top of my existing posting system in PHP?

Status
Not open for further replies.
Messages
89
Reaction score
0
Points
6
I have a page where the latest status updates by my friends and me are displayed.

The tables involved are statusUpdates, users & friends.

The script I used to pull the necessary data was -

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");

And I printed the data using this -

Code:
if (mysql_num_rows($myQuery) == 0) echo "No updates";
else
{
	while ($row = mysql_fetch_assoc($myQuery))
	{
		// Print $row['statusID'], $row['status'], $row['authorID'], $row['fullName'], $row['userProfileLink'], etc
	}
}

Now I am also thinking of incorporating a commenting system.
For that I will be creating a new table comments with the following fields - commentID, targetStatusID, commentorID, comment, commentTimeStamp

How should I adjust my mysql queries so that the comments for each status update also get printed out in the following way -

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]

Please note that

commentID is the primary key.
targetStatusID indicates the particular status update on which the comment was made.
commentorID is the ID of the person who commented.
comment is the actual content.
commentTimeStamp shows the time when the comment was made.

By the way, I would like to achieve the whole thing using procedural programming, and not OOP.

One of the ways to solve this would be by using a query inside while ($row = mysql_fetch_assoc($myQuery)) to select comments for $row['statusID'].

But that would build up the number of queries if I wanted to display many posts.

So what should my approach be?
 
Last edited:

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Why? What's the incentive? You've dictated the style, so learning isn't on your agenda — you want the code written for you, and this isn't a rent-a-coder site. You're also using ext/mysql (mysql_xxxx()), which is already deprecated in PHP 5.5, despite previous advice not to.
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Ah, so you want other people to do your homework for you? <sarcasm level="utter-complete">That really makes me want to help.</sarcasm>
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
Or perhaps not.

Thread locked, we don't do people's homework here as that is usually considered cheating.
 
Status
Not open for further replies.
Top