简体   繁体   中英

Display threaded comments with MySQL & PHP

Given the following table, how can write a MySQL query to display threaded comments in a single page?

Table structure:

  • comment_id
  • comment_parent
  • comment_content

Thank you.

Select comment_content from table where comment_parent != 0;

然后使用PHP显示所需的结果。

Depending on how deep you want to go ... but here is a 1-thread example to do with 1 query

SELECT * FROM `comment` a LEFT JOIN `comment` b ON a.comment_id = b.comment_id WHERE a.comment_parent = 0 

then use php to select wether the parent comment changes and display that.

but it would likely be better to do this over multiple queries for speed. you would need to do some benchmarks to be sure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM