Hi the whole day I've been trying to find a solution. I have tried this Nested array. Third level is disappearing and this Trying to get threaded/nested comments in PHP and many other ways but may be due to my lack of knowledge I could not get the needed result. And that's why I'm asking for help. I want to create nesting comments for my News Website.
I have a table in mySQL with CommentID and ParentID
Have a Class Post where I'm getting all the assigned comments
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;
That is the array I'm getting form $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
)
)
)
And this is the error I'm getting every time I'm trying to do anything with this array
Fatal error: Cannot use object of type comment as array in /Applications/MAMP/htdocs/News/includes/thread.php on line 15
the Thread.PHP is an exact copy of http://www.jongales.com/blog/2009/01/27/php-class-for-threaded-comments/
Could anyone help me please.
Thank you.