Hi everyone, I hope I can explain. Please help me for this. any idea or help can safe my life. thanks.
I have 3 mysql table (users and categories the others. total is 5). contents, comments, votes.
so I pull the content and then comments of the content and then votes for the comments.
What I would like to do is answering system for the comments. similar to reddit or youtube comments.
my comment table is this
CommentsID - ContentsID - UserID - Comment - Time - Parent - WriteIP - Active -TotalVotes - VoteSum
Parent come from CommentsID
So, this is Hierarchical Data. But i cannot figure out how can I display this.
this is my query
$Where = array( "ct.ContentsID = '" . $Contents['ContentsID'] . "'" );
if ( $_SESSION['UserID'] == 0 )
$Where[] = "ct.Active = '1'";
else if ( $_SESSION['Level'] < 3 )
$Where[] = "(ct.Active = '1' OR ct.UserID = '" . $_SESSION['UserID'] . "')";
else
{
$THEME->loadJS( 'Ajax.js' );
$THEME->loadJS( 'Moderate.js' );
}
$sql = mysql_query( "SELECT ct.*, ut.*, vt.UserID UserVote FROM comments ct
INNER JOIN users ut ON ut.UserID = ct.UserID
LEFT JOIN voters vt ON ( vt.CommentsID = ct.CommentsID AND vt.UserID = '" . $_SESSION['UserID'] . "' )
LEFT JOIN comments cp ON ( ct.Parent = cp.CommentsID )
WHERE " . implode( ' AND ', $Where ) . " ORDER BY Time DESC" );
and this is how I display everything
if ( !$sql ) echo mysql_error();
if ( mysql_num_rows( $sql ) )
{
$Contents = array();
$Count = 0;
$LoadVoteJS = false;
while ( $ROW = mysql_fetch_array( $sql ) )
{
$Status = '';
$WriteTime = $ROW['Time'] > 0 ? date( 'd.m.Y H:i:s', $ROW['Time'] ) : '';
$Content = preg_replace( '/tag:“([^&]+)̶[01];/ie', "'<a href=\"/tag/'.tagPointer('\\1').'.html\">\\1</a>'", $ROW['Comment'] );
$Vote = "";
if ( $ROW['Active'] == '0' )
$Status = $_SESSION['Level'] >= 3 ? '<a onClick="MsgOnayla(\'' . $ROW['CommentID'] . '\',this);" style="cursor:pointer">Onayla!</a> <a onClick="MsgSil(\'' . $ROW['CommentID'] . '\',this);" style="cursor:pointer">Sil!</a>' : 'Onay Bekliyor!';
else if ( $_SESSION['Level'] >= 1 )
{
if ( is_null( $ROW['UserVote'] ) AND $ROW['UserID'] != $_SESSION['UserID'] )
{
$LoadVoteJS = true;
$Status = '<span id="voteContent-' . $ROW['CommentID'] . '">[ <a onClick="MsgOyla(\'' . $ROW['CommentID'] . '\',\'1\');" style="cursor:pointer">?yi!</a> | <a onClick="MsgOyla(\'' . $ROW['ContentID'] . '\',\'0\');" style="cursor:pointer">Kötü!</a> ]</span> ';
}
else if ( $ROW['TotalVotes'] > 0 )
$Vote = "%" . intval( 100 * ( $ROW['VoteSum'] / $ROW['TotalVotes'] ) );
}
if ($ROW['Active'] == '1')
$Oparation = $_SESSION['Level'] >= 3 ? '<a onClick="MsgSil(\'' . $ROW['CommentID'] . '\',this);" style="cursor:pointer"><img src="/Themes/Standart/Image/delete_content.gif"></a>' : '';
if ($_SESSION['UserID'] != $ROW['UserID'])
$Message = $_SESSION['Level'] >= 1 ? '<a href="/Message/?senduser='.$ROW['UserID'].'">Mesaj</a>' : '';
$Name = '<a href="/User/profile.php?id='.$ROW['UserID'].'">'.$ROW['Username'].'</a>';
$Contents[] = t_ContentBox( $Content, $Name, $WriteTime, $Status, $Vote, $Message, $Oparation );
if ( $Count++ == 0 AND $_SESSION['Level'] < 3 )
$Contents[] = t_ContentBanner();
}
if ( $LoadVoteJS )
{
$THEME->loadJS( 'Ajax.js' );
$THEME->loadJS( 'Vote.js' );
}
$_PAGE .= t_commentinfo(mysql_num_rows($sql));
$_PAGE .= t_Contents( implode( t_ContentSeperator(), $Contents ), $CommentForm, $Title );
}