php – 如何在循环中的注释上输出注释?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 如何在循环中的注释上输出注释?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_419_6@ 参见英文答案 > What is the most efficient/elegant way to parse a flat table into a tree?                                    14个
结构表评论

id (int 11)
NewsIdn (vArchar 10)
CommentsIdn (VARchar 10) //
ForCommentsIdn (varchar 10) //have CommentsIdn comments(answers) reply to which users 
Text (varchar 100)
DateCreate (datetime)

我想输出评论评论(答案),即.页面上的结构输出数据:

-- comment 1
-----answer on comment 1
--------answer on answer on comment 1 (№1)
--------answer on answer on comment 1 (№2)
--------answer on answer on comment 1 (№3)
----------answer on answer №3 on answer on comment 1
-------------
---------------N
                       ***
                       ***
                       ***
-- comment 2
-----answer on comment 2
--------answer on answer on comment 2 (№1)
--------answer on answer on comment 2 (№2)
--------answer on answer on comment 2 (№3)
----------answer on answer №3 on answer on comment 2
-------------
---------------N

                       ***
                       ***
                       ***
-- comment N
-----answer on comment N
--------answer on answer on comment N (№1)
--------answer on answer on comment N (№2)
--------answer on answer on comment N (№3)
----------answer on answer №3 on answer on comment N

AND IE.

我得到第一个评论

SELECT * From COMMENTS WHERE NewsIdn='1122121' // value NewsIdn as example

但是如何在循环中输出对注释的评论

请告诉我怎么做?

解决方法

是的,你必须要正常化……
我为你创建了一些表格.

@L_512_13@表

id(PK) name  

新闻表

id (int 11)
Text
DateCreate (datetime)
user_id(FK wITh user table)

评论

id (int 11)
Text
DateCreate (datetime)
news_id(int 11)(FK with news table)
user_id

评论表的子评论

id (int 11)
comments_id(FK with comments table)
Text
user_id(int)(FK with user table)
DateCreate (datetime)

现在为每条评论写下以下查询

对于循环,只需在注释表中使用一个循环.然后你得到每个评论的所有答案.

$query=query("select id from news");
while($q=MysqL_fetch_assoc($query)){
//Here is each news
$query1=query("SELECT comments_id,comments FROM comments c WHERE c.news_id=$q['id']");
//Here is each comment
   while($q1=MysqL_fetch_assoc($query1)){
   $query2=query("
                  SELECT sub.text,u.user_name FROM sub_comments AS sub
                  LEFT JOIN comments AS c
                  ON c.id=sub.COMments_id
                  INNER JOIN user AS u
                  ON u.id=sub.user_id
                  WHERE c.id=$q1['comments_id']
                 ");
                 while($q2=MysqL_fetch_assoc($query2)){
                    //Here are sub comments for each comments  
                    PRint $q2['text'];
                 }
    }
}

脚本宝典总结

以上是脚本宝典为你收集整理的php – 如何在循环中的注释上输出注释?全部内容,希望文章能够帮你解决php – 如何在循环中的注释上输出注释?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。