嗨一整天我一直在努力寻找解决方案。我试过这个 嵌套数组。第三级正在消失 ,这试图在 PHP和许多其他方式中获取线程/嵌套注释,但可能是由于我缺乏知识,我无法获得所需的结果。这就是我寻求帮助的原因。我想为我的新闻网站创建嵌套评论。
我在 mySQL 中有一个带有 CommentID 和 ParentID 的表
有一个班级帖子,我可以在其中获得所有指定的评论
case Comments:
if ($this->iPostID != 0) {
$sSQL = "SELECT CommentID, ParentID FROM Comment WHERE PostID=" . $this->iPostID;
$rsComment = $this->dDatabase->query($sSQL);
while ($aComment = $this->dDatabase->fetch_array($rsComment)) {
$sComment = new comment();
$sComment->load($aComment['CommentID']);
$this->aComments[] = $sComment;
}
}
return $this->aComments;
break;
那就是我从 $this->aComments 中得到的数组:
Array
(
[0] => comment Object
(
[iCommentID:comment:private] => 1
[iDatePosted:comment:private] => 17 July 2012
[sContent:comment:private] => Very nice it works now
[iUserID:comment:private] => 1
[iPostID:comment:private] => 1
[iParentID:comment:private] => 0
[dDatabase:comment:private] => database Object
(
[sqliConnection:database:private] => mysqli Object
(
[affected_rows] => 1
[client_info] => 5.5.9
[client_version] => 50509
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[field_count] => 6
[host_info] => Localhost via UNIX socket
[info] =>
[insert_id] => 0
[server_info] => 5.5.9
[server_version] => 50509
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 2929
[warning_count] => 0
)
)
)
...
[3] => comment Object
(
[iCommentID:comment:private] => 4
[iDatePosted:comment:private] => 22 July 2012
[sContent:comment:private] => thies is the first reply for a comment
[iUserID:comment:private] => 4
[iPostID:comment:private] => 1
[iParentID:comment:private] => 1
[dDatabase:comment:private] => database Object
(
[sqliConnection:database:private] => mysqli Object
(
[affected_rows] => 1
[client_info] => 5.5.9
[client_version] => 50509
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[field_count] => 6
[host_info] => Localhost via UNIX socket
[info] =>
[insert_id] => 0
[server_info] => 5.5.9
[server_version] => 50509
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 2929
[warning_count] => 0
)
)
)
这是我每次尝试对这个数组做任何事情时都会遇到的错误
致命错误:无法在第 15 行的 /Applications/MAMP/htdocs/News/includes/thread.php 中使用注释类型的对象作为数组
Thread.PHP 是http://www.jongales.com/blog/2009/01/27/php-class-for-threaded-comments/的精确副本
谁能帮帮我。
谢谢你。