On Sat, 20 Apr 2002, Julio Nobrega wrote:
> I have maybe an easy to solve problem, but I haven't come with a logical
> way to do it. I am builing a discussion site (a la Kuro5hin.org), and
> there's a sql query to retrieve comments attached to an article. It grabs
> their titles, along with some more informatio. What I want is to display the
> comments and the replies below them. It's been implemented in thousands of
> other scripts, but I can't figure out how to do with only one sql query
> (even if it uses Joins). That's important, since I expect the site to be
> very popular here in Brazil (let's hope!)
>   So, any advices about how to display the comments like this:
> - Comment 1
>   - Comment 2
>     - Comment 3
> Is greatly appreciated. I am thinking about storing all comments in an
> array and construct the layout from there. But still, I don't know if it's
> the best choice in performance terms.

Well, which database are you using? Oracle supports hierarchical queries 
which are a pretty easy way to accomplish it with just SQL.

If your RDBMS doesn't support that, you're probably stuck doing a select
order by parent_id and then shuffling the resulting clusters around in
PHP. Use a 3D array (parent/id/content).


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to