cheapbag214s |
Wysłany: Pon 2:40, 02 Wrz 2013 Temat postu: Multi Threaded Comments PHP |
|
Multi Threaded Comments PHP,デュベティカダウンジャケット
I have a script I wrote I while back for comments,ダウンジャケットduvetica, but it is only single threaded. I would like it to be multi-threaded,デュベティカ 店舗, but only as so a user can reply to a comment,デュベチカ 通販, not so a user can reply to a comment of a comment. So the threads would only be two deep.
Currently I store a comment_id against a user_id in my database,デュベティカ 激安.
The only way I can think of to do the multi threaded comments,ダウンジャケットduvetica, is to have a parent field in the comments table. But if I do this then when I am selecting the comments with PHP,デュベチカ 通販, I will have to do another SELECT command to select the comments children (if any) for each comment. Seems like a lot of work on the database.
There has to be a better way,デュベチカ専売店. Any ideas on this,デュベチカ 通販? Or tutorials?
A recursive query to select all comments based on their parent ids,デュベチカ 通販. This is supported by many database products and the syntax depends on the database type,discount Men And Women Parajumpers Jackets Outlet On Sale 2013. Check the docs for more info (search for 'recursive'),ダウンジャケットレディース.
If you store the article id in each (sub-)comment,デュベティカアウトレット, you can just select all comments with the article id in one regular select query. You can use the parent ids to properly display the comments on the page under the right parent comment:
SELECT * FROM comments WHERE article_id = :article_id
If you only need two levels of comments, you can use an extended where to include both first level and second level comments:
SELECT * FROM comments
WHERE parent_id = :article_id
OR parent_id IN (SELECT id FROM comments WHERE parent_id = :article_id)
It is also possible to use union all to combine two queries that have the same columns,デュベティカ ダウンジャケット, but since I assume that all data are from the same table,デュベティカ 激安, there is probably no need for it (see the extended where-clause above):
SELECT * FROM comments WHERE parent_id = :article_id
UNION ALL
SELECT * FROM comments WHERE parent_id IN
(SELECT id FROM comments WHERE parent_id = :article_id)
Personally,デュベティカアウトレット, I would go for option 2 because it is simple (no exotic SQL construct required), efficient (1 query) and flexible (supports as many levels of comments as you like).
This is a common use for hierarchical,デュベティカアウトレット, or tree-structure data. I wrote a popular answer to this Stack Overflow question: What is the most efficient/elegant way to parse a flat table into a tree?
I also wrote a presentation describing alternatives for tree-structured data: Models for Hierarchical Data with SQL and PHP,デュベティカ 店舗 東京.
Another solution that is not included in my presentation is the way Slashdot does threaded comments. They use a parent column like you do,デュベティカアウトレット, so each comment references the comment it replies to. But then they also include a root column so each comment knows the post it belongs to. There are seldom more than a few hundred comments on a given post,デュベティカダウンジャケット, and usually you want to get the whole tree of comments for a given post starting at the top of the comment thread:
相关的主题文章:
http://www.zgdhc.com/bbs/boke.asp?scheapk11588.showtopic.132883.html
http://cpaz.org.cn/
http://bbs.zhaoyuan.cn/
http://puk.com.cn/forum.php?mod=viewthread&tid=1216083
http://www.thepodhotel.com/podculture/node/85396/current-revision
http://forum.hivarobotics.com/
http://www.fesghelchat.com/cloob/
http://www.aipsys.com/forum/newtopic.html
http://park11.wakwak.com/~yda/cgi-bin/kokoa/keitaibbs/epad.cgi?mode=view&no=1118664&res=1&page=400
http://www.uu2.cn/
http://nepalhealth.com/index.php?option=com_fireboard&Itemid=85&func=view&catid=15&id=104278#104278
http://www.52qidian.com/bbs/forum.php?mod=viewthread&tid=3452431
http://www.alemturk.net/showthread.php?p=9885#post9885
http://21auto.com.cn/bbs/
http://studio.radube.com/spam/denied |
|