ADVANCED TREE COMMENT SYSTEM WITH CSS ,PHP & MYSQL
=====================================================
I have created output version of tree comment system direct from db. Input version will be coming soon.
DB
Create two tables status and status_comment
Table status
-------------
Table comment
--------------------
First CSS
------------
<style type="text/css">
.comment_row{
margin-bottom: 10px;
padding: 10px;
background-color: #f2f2f2;
border:1px solid #4d4d4d;
}
.comment_row .comment_card{
-webkit-box-shadow: inset 0px 0px 10px 1px rgba(58,55,101,1);
-moz-box-shadow: inset 0px 0px 10px 1px rgba(58,55,101,1);
box-shadow: inset 0px 0px 10px 1px rgba(58,55,101,1);
color: #fff;
}
.comment_row .comment_card {
border-radius: 3px;
background-color: #6863ae;
padding: 5px;
}
.comment_row .comment_card .comment_row1,.comment_row .comment_card .comment_row2,.comment_row .comment_card .comment_row3{
width: 100%;
color: #fff;
}
.comment_row .comment_card table th,td{
}
.comment_row .comment_card .comment_profile_pic{
width: 45px;
border:1px solid #fff;
}
.comment_row .comment_options{
width: 40px;
}
.comment_row .comment_fullname,.comment_row .comment_timeago{
width:100%;
}
.comment_row .line{
width: 100%;
border-top: 1px solid #4b487d;
margin-top: 5px;
margin-bottom: 5px;
}
.comment_row .comment_card .comment_row3 .comment_properties2{ text-align: right; }
</style>
Now PHP
-------------
<?php
include('DB/db_conx.php');
$user_id="29";
$statuslist="";
$sql_user = "SELECT id from status where user_id='".$user_id."' order by postdate desc ";
$query_user = mysqli_query($db_conx, $sql_user);
while ($row3 = mysqli_fetch_array($query_user, MYSQLI_ASSOC))
{
$id= $row3["id"];
$result = mysqli_query($db_conx,"SELECT * FROM status_comment WHERE thread_id ='".$id."' ");
$comments = array();
while ($row = mysqli_fetch_array($result)) {
$foo="";
$row['thread_id'] = array();
$comments[$row['id']] = $row;
$comment_id=$row['id'];
// $id_thread= $row['thread_id'];
}
// into its parent_id
foreach ($comments as $k => &$v) {
if ($v['parent_id'] != 0) {
$comments[$v['parent_id']]['thread_id'][] =& $v;
}
}
unset($v);
// delete the thread_id comments from the top level
foreach ($comments as $k => $v) {
if ($v['parent_id'] != 0) {
unset($comments[$k]);
}
}
/*include_once("get_comment_function.php"); ----------- > you can use include_once for separate php file ,if you dont want function in same php file.As for now i wrote function in same single php file.*/
if(!function_exists('display_comments'))
{
// now we display the comments list, this is a basic recursive function
function display_comments(array $comments, $level = 0) {
$foo="";
$com_box='';
Global $foo;
foreach ($comments as $info) {
$com_box='';
//$comment_card=$info['id']." ". $info['msg']." ". $info['likes']." ". $info['posted_on'] ;
$example_card='
<div class="comment_card">
<table class="comment_row1">
<tr>
<td class="comment_profile_pic"><img src="images/profile.png"/></td>
<td><div class="comment_fullname">1</div>
<div class="comment_timeago">'.$info['posted_on'] .'</div>
</td>
<td class="comment_options">'.$info['id'].'</td>
</tr>
</table>
<table class="comment_row2">
<tr>
<td class="comment_msg">'.$info['msg'].'</td>
</tr>
</table>
<div class="line"></div>
<table class="comment_row3">
<tr>
<td class="comment_properties1"> '. $info['likes'].' Love </td>
<td class="comment_properties2"> To akash Khandavilli </td>
</tr>
</table>
</div>
';
//$com= str_repeat('-', $level + 1).$example_card.;
$table='<table width="100%"><tr> <td>'.str_repeat('-', $level + 1).'</td><td>
'.$example_card.'</td> </tr></table>';
$com_box.=$table;
//echo $com_box;
$com_box= str_replace("-", " ", $com_box);
$foo.=$com_box ;
if (!empty($info['thread_id'])) {
display_comments($info['thread_id'], $level + 1);
}
}
return $foo;
}
}
display_comments($comments);
$statuslist.='<div>Post_id:'.$id.'</div><div class="comment_row">Comment_id:'. $comment_id.'----comment-msg:'. $foo .'</div>';
}
echo $statuslist;
?>
[ If you like my work please donate :) you can see donate button on top left side ]
=====================================================
I have created output version of tree comment system direct from db. Input version will be coming soon.
DB
Create two tables status and status_comment
Table status
-------------
Table comment
--------------------
OUTPUT
----------------
------------
<style type="text/css">
.comment_row{
margin-bottom: 10px;
padding: 10px;
background-color: #f2f2f2;
border:1px solid #4d4d4d;
}
.comment_row .comment_card{
-webkit-box-shadow: inset 0px 0px 10px 1px rgba(58,55,101,1);
-moz-box-shadow: inset 0px 0px 10px 1px rgba(58,55,101,1);
box-shadow: inset 0px 0px 10px 1px rgba(58,55,101,1);
color: #fff;
}
.comment_row .comment_card {
border-radius: 3px;
background-color: #6863ae;
padding: 5px;
}
.comment_row .comment_card .comment_row1,.comment_row .comment_card .comment_row2,.comment_row .comment_card .comment_row3{
width: 100%;
color: #fff;
}
.comment_row .comment_card table th,td{
}
.comment_row .comment_card .comment_profile_pic{
width: 45px;
border:1px solid #fff;
}
.comment_row .comment_options{
width: 40px;
}
.comment_row .comment_fullname,.comment_row .comment_timeago{
width:100%;
}
.comment_row .line{
width: 100%;
border-top: 1px solid #4b487d;
margin-top: 5px;
margin-bottom: 5px;
}
.comment_row .comment_card .comment_row3 .comment_properties2{ text-align: right; }
</style>
Now PHP
-------------
<?php
include('DB/db_conx.php');
$user_id="29";
$statuslist="";
$sql_user = "SELECT id from status where user_id='".$user_id."' order by postdate desc ";
$query_user = mysqli_query($db_conx, $sql_user);
while ($row3 = mysqli_fetch_array($query_user, MYSQLI_ASSOC))
{
$id= $row3["id"];
$result = mysqli_query($db_conx,"SELECT * FROM status_comment WHERE thread_id ='".$id."' ");
$comments = array();
while ($row = mysqli_fetch_array($result)) {
$foo="";
$row['thread_id'] = array();
$comments[$row['id']] = $row;
$comment_id=$row['id'];
// $id_thread= $row['thread_id'];
}
// into its parent_id
foreach ($comments as $k => &$v) {
if ($v['parent_id'] != 0) {
$comments[$v['parent_id']]['thread_id'][] =& $v;
}
}
unset($v);
// delete the thread_id comments from the top level
foreach ($comments as $k => $v) {
if ($v['parent_id'] != 0) {
unset($comments[$k]);
}
}
/*include_once("get_comment_function.php"); ----------- > you can use include_once for separate php file ,if you dont want function in same php file.As for now i wrote function in same single php file.*/
if(!function_exists('display_comments'))
{
// now we display the comments list, this is a basic recursive function
function display_comments(array $comments, $level = 0) {
$foo="";
$com_box='';
Global $foo;
foreach ($comments as $info) {
$com_box='';
//$comment_card=$info['id']." ". $info['msg']." ". $info['likes']." ". $info['posted_on'] ;
$example_card='
<div class="comment_card">
<table class="comment_row1">
<tr>
<td class="comment_profile_pic"><img src="images/profile.png"/></td>
<td><div class="comment_fullname">1</div>
<div class="comment_timeago">'.$info['posted_on'] .'</div>
</td>
<td class="comment_options">'.$info['id'].'</td>
</tr>
</table>
<table class="comment_row2">
<tr>
<td class="comment_msg">'.$info['msg'].'</td>
</tr>
</table>
<div class="line"></div>
<table class="comment_row3">
<tr>
<td class="comment_properties1"> '. $info['likes'].' Love </td>
<td class="comment_properties2"> To akash Khandavilli </td>
</tr>
</table>
</div>
';
//$com= str_repeat('-', $level + 1).$example_card.;
$table='<table width="100%"><tr> <td>'.str_repeat('-', $level + 1).'</td><td>
'.$example_card.'</td> </tr></table>';
$com_box.=$table;
//echo $com_box;
$com_box= str_replace("-", " ", $com_box);
$foo.=$com_box ;
if (!empty($info['thread_id'])) {
display_comments($info['thread_id'], $level + 1);
}
}
return $foo;
}
}
display_comments($comments);
$statuslist.='<div>Post_id:'.$id.'</div><div class="comment_row">Comment_id:'. $comment_id.'----comment-msg:'. $foo .'</div>';
}
echo $statuslist;
?>
[ If you like my work please donate :) you can see donate button on top left side ]