gdebojyoti.mail96
Member
- 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 -
And I printed the data using this -
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 -
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?
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: