Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何回复评论?(菲律宾)_Php_Mysql - Fatal编程技术网

Php 如何回复评论?(菲律宾)

Php 如何回复评论?(菲律宾),php,mysql,Php,Mysql,我想创建一些东西,比如他们有评论的地方,然后回复评论,然后回复回复 他们使用哪种类型的数据库结构: 1. they keep track of all the comments to a posting 2. a reply to a comment 3. a reply to a reply 我所拥有的权利只是一个帖子和一堆与之相关的评论,比如 POSTING TABLE posting_id | title | author COMMENTS TABLE comment_id | pos

我想创建一些东西,比如他们有评论的地方,然后回复评论,然后回复回复

他们使用哪种类型的数据库结构:

1. they keep track of all the comments to a posting
2. a reply to a comment
3. a reply to a reply
我所拥有的权利只是一个帖子和一堆与之相关的评论,比如

POSTING TABLE
posting_id | title | author

COMMENTS TABLE
comment_id | posting_id | comment

REPLIES TABLE
????
我如何将评论与回复联系起来? 他们使用什么类型的css来提供缩进空间的回复

编辑: 谢谢你的回答!现在我唯一的问题是如何缩进回复? 例如

you like food
     yes I love italian
        Yes i do like it too
     chinese is best

您可以在注释表中添加另一列,指定父注释id,并在其中填充用户要回复的注释(或回复)的id。如果评论是对帖子的直接回复(而不是回复评论),则此列将为空。

在评论表中添加另一个“回复”或类似的字段,并将其回复的评论的id存储在该字段中。

您可以将评论表设置为通用字段,如下所示:

COMMENTS TABLE
comment_id | posting_type | posting_id | comment
其中,posting_type是某种类型的鉴别器,例如字符串“POST”或“COMMENT”,或一个更高效的整数(1=POST,2=COMMENT,等等)


编辑:无可否认,这更为复杂,但这意味着你可以对任何内容使用相同的评论表,而不仅仅是帖子和其他评论。

你不需要回复表。正如其他人已经正确指出的那样,递归是使用RDBMS的方式。你总是可以考虑使用NoSQL风格的DBMS,以避免必须处理递归。

< P>我会做一个交叉引用表。

例如:

表:员额

列:pstkey | userid | postMessage |等。。。 pstkey是柱体的键。userid是创建帖子的人。postMessage是实际的post条目

表:评论

栏目:comkey | pstkey | userid | commentMessage |等。。。 comkey是评论的关键。使用pstkey引用文章。userid是发表评论的人。然后commentMessage是实际注释的文本体

表:外部参照后命令

列:xrefkey | pstkey | comkey | comkey2 | 现在来看有趣的部分。所有的柱子都放在柱子上。所有注释都进入注释表。这些关系都在交叉引用表中定义

我所有的编程都是这样做的。我有幸和一位退休的世界上最好的数据库工程师一起工作,他教了我一些技巧

如何使用交叉参考表:

xrefkey | pstkey | comkey | comkey2 你所寻找的只是某一特定领域的人口。 外部参照(自动递增) pstkey(包含帖子的pstkey) comkey(包含评论文章的comkey) comkey2(包含评论文章的comkey) (但仅当comkey已经有值时才填充comkey2) 当然,您可以使用注释的键填充comkey2。 看,没有理由要第三个标签! 使用此方法,您可以添加任意数量的关系。 现在或将来! comkey2是您对回复的回复。这一行包含的。。。。帖子的键、评论的键和回复评论的键。所有这些都是由外部参照的填充完成的

EXAMPLE: PAGES.... Page table POSTS pstkey | pageid | user| Post ------------------------------------- | 1 | 1 | 45 | Went to the store the....| | 2 | 2 | 18 | Saw an apple on tv..... COMMENTS comkey | pstkey | user | Comment ----------------------------------------------- | 1 | 1 | 9 | Wanted to say thanks... | 2 | 1 | 7 | Cool I like tha..... | 3 | 2 | 3 | Great seeing ya.... | 4 | 2 | 6 | Had a great.... | 5 | 2 | 2 | Don't sweat it man... xref_PostCom xrefkey | pageid | pstkey | comkey | comkey2 | ---------------------------------------------- | 1 | 1 | 1 | NULL | NULL | Post1 on Page1 | 2 | 1 | 1 | 1 | NULL | Comment1 under Post1 | 3 | 1 | 1 | 2 | NULL | Comment2 under Post1 | 4 | 2 | 2 | NULL | NULL | Post2 on Page2 | 5 | 2 | 2 | 3 | NULL | Comment3 under Post2 on Page2 | 6 | 2 | 2 | 4 | NULL | Comment4 under Post2 on Page2 (a second Comment) | 7 | 2 | 2 | 4 | 5 | Explained below.... Comment key 5 is matched with comment key 4....under post2 on Page 2 例子: 页。。。。页表 帖子 pstkey |页面ID |用户|帖子 ------------------------------------- |1 | 1 | 45 |去了| |2 | 2 | 18 |在电视上看到一个苹果。。。。。 评论 comkey | pstkey |用户|评论 ----------------------------------------------- |1 | 1 | 9 |想说声谢谢。。。 |2 | 1 | 7 |酷我喜欢。。。。。 |3 | 2 | 3 |很高兴见到你。。。。 |4 | 2 | 6 |有一个伟大的。。。。 |5 | 2 | 2 |别担心,伙计。。。 外部参照邮政编码 xrefkey | pageid | pstkey | comkey | comkey2| ---------------------------------------------- |1 | 1 | 1 | NULL | NULL |第1页的Post1 |Post1下的2 | 1 | 1 |空|注释1 |Post1下的3 | 1 | 1 | 2 |空|评论2 |4 | 2 | 2 |空|空|第2页第2篇 |5 | 2 | 2 | 3 |空|评论3在第2页的Post2下 |第2页Post2下的6 | 2 | 2 | 4 |空|注释4(第二条注释) |7 | 2 | 2 | 4 | 5 |解释如下。。。。 注释键5与第2页post2下的注释键4匹配 如果您了解join、left join、right join、internal/outer join创建SELECT以使用这些关系获取数据数组,那么您的工作就会简单得多

我相信工程师称之为定义关系的“数据地图”。现在的诀窍是如何使用这些关系访问它们。一开始很难,但知道我知道什么,我拒绝用其他方式

最后的结果是你写了一个剧本,上面写着,好吧,去做,嗯,所有的事情,然后回来。您将以1个函数调用结束,该函数调用请求第1页。它返回page1、post 1、comment1、comment2和comment3以及1数组中回复的回复。回显到输出并完成

更新以供评论 第一次给我看的时候我说了同样的话。事实上,数据库程序员强迫我这样做真的让我很生气。但现在我明白了。优势是如此之多

优点1)可以编写1个查询,以便在一次拍摄中将其全部提取出来

2) 多个查询中的答案可以填充结构中的数组,在打印页面时,循环中的循环可以显示页面

3) 升级使用它的软件可以支持您所能想到的任何可能的设计更改。完美的可扩展性

教我的那个人是重新设计西尔斯和jcpenny数据库的雇工。当他们因为重复记录的问题有9本书去同一家时

交叉引用表防止了l Columns: comkey | pstkey | userid | commentMessage | etc... Columns: xrefkey | pstkey | comkey | comkey2 | xrefkey | pstkey | comkey | comkey2 All that you look for is the population of a given field. xref (Auto Incremented) pstkey (Contains the pstkey for the post) comkey (Contains the comkey for the comment post) comkey2 (Contains the comkey for the comment post) (but only populate comkey2 if comkey already has a value) and of course you populate comkey2 with the key of the comment. SEE, no reason for a 3rd tabel! With this method you can add as many relationships as you want. Now or in the future! EXAMPLE: PAGES.... Page table POSTS pstkey | pageid | user| Post ------------------------------------- | 1 | 1 | 45 | Went to the store the....| | 2 | 2 | 18 | Saw an apple on tv..... COMMENTS comkey | pstkey | user | Comment ----------------------------------------------- | 1 | 1 | 9 | Wanted to say thanks... | 2 | 1 | 7 | Cool I like tha..... | 3 | 2 | 3 | Great seeing ya.... | 4 | 2 | 6 | Had a great.... | 5 | 2 | 2 | Don't sweat it man... xref_PostCom xrefkey | pageid | pstkey | comkey | comkey2 | ---------------------------------------------- | 1 | 1 | 1 | NULL | NULL | Post1 on Page1 | 2 | 1 | 1 | 1 | NULL | Comment1 under Post1 | 3 | 1 | 1 | 2 | NULL | Comment2 under Post1 | 4 | 2 | 2 | NULL | NULL | Post2 on Page2 | 5 | 2 | 2 | 3 | NULL | Comment3 under Post2 on Page2 | 6 | 2 | 2 | 4 | NULL | Comment4 under Post2 on Page2 (a second Comment) | 7 | 2 | 2 | 4 | 5 | Explained below.... Comment key 5 is matched with comment key 4....under post2 on Page 2
function get_comments($comment_id) {
    print '<div class="comment_body">';

    // print comment body or something?

    if (comment_has_reply($comment_id)) {
        foreach(comment_comments($comment_id) as $comment) {
            get_comments($comment->id);
        }
    }

    print '</div>';
}
<style type="text/css">
.comment_body {
    margin-left:10px;
}
</style>