|
pseudo-code help
Date: 09/18/05
(PHP Community) Keywords: php, mysql, blogging, sql
I'm making a threaded comments script for a blogging system. My code so
far is not working, so I'm trying to think it through again using
pseudo-code. I'd really appreciate some feedback on what I should be
doing, if anyone would mind taking a look at the pseudo-code (under the
cut). If my reasoning is correct, then I can concentrate on the syntax.
MySQL tables:
Posts (sorry for the yuck formatting)
Comments
id (unique id)
|
post (to which the comment belongs)
|
parent (comment to which the comment is a reply)
|
author
|
title
|
timestamp
|
email
|
homepage
|
content |
Coding
- have a script, PostsTable.php, to display a post or posts using a while loop, including a collapsible division to display comments or not as desired (easy - done that)
- for each post, set the parent value, $parent_id, to 0 as part of the while loop
- for each post, set the ID of the post, $post_id, from the array generated by the query used to get the post
- within the comments division below each post, include a script, CommentsView.php, to run the queries to get comments
- use a while loop in CommentsView.php to get all comments in order and in accordance with $parent_id and $post_id
- for each comment, set its ID (within the loop) as $parent_id for looping through its replies later
- if there are no comments for a particular post (or replies to a particular comment), end
- if there are comments, include a script to display them similar in design to PostsTable.php: CommentsTable.php
- CommentsTable.php includes CommentsView.php, until it ends
Thank you in advance ^^
Source: http://www.livejournal.com/community/php/344263.html
|