Antes que nada la estructura de los mensajes que vendria a ser el include functions.php:
Código PHP:
<?php
function showComment($arr)
{
date_default_timezone_set("America/Lima");
$hace = new tiempoTrasncurrido($arr['post_date'],'s');
if (isset($_SESSION['signed_in']))
{
$comments_resultadou = mysql_query("SELECT *
FROM
users
WHERE user_id = ".$_SESSION['user_id']."");
while($rowu=mysql_fetch_assoc($comments_resultadou)){
$user_id = $rowu['user_id'];
$user_name = $rowu['user_name'];
$user_foto = $rowu['user_foto'];
}
}
$sql = "SELECT
topic_id,
topic_subject,
topic_cat,
media,
total_estrellas,
votos
FROM
topics
WHERE
topics.topic_id = " . mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
while($rowtop = mysql_fetch_assoc($result))
{
$topic_cat = $rowtop['topic_cat'];
$topic_id = $rowtop['topic_id'];
$num=mysql_query("SELECT * FROM posts WHERE post_topic = '".$topic_id."' ")or die(mysql_error());
$numeromsj=mysql_num_rows($num);
$totmsj = $numeromsj - 1;
echo '<div class="waveComment com-'.$arr['post_id'].'">';
echo '<div class="comment">';
?>
<?php
if($arr['cat_post'] !=0 ){
echo '<div class="waveTime">Hace '.$hace.'</div>';
echo '<div class="commentAvatar">
<img src="imagen/user/'.$arr['user_foto'].'" class="user_comment" alt="'.$arr['usr'].'" />
</div>
<div class="commentText">
<span class="name">@<a href="perfil.php?id='.$arr['user_id'].'">'.$arr['usr'].'</a></span><br><span id="contenido" >'.bbcode($arr['post_content']).'</span>
</div>';
?>
<?php
if (isset($_SESSION['signed_in']))
{
echo '<div class="replyLink">
<a href="javascript:void(0);" onClick="addComment(this,\''.$arr['post_id'].'\',\''.$user_id.'\',\''.$user_name.'\',\''.$user_foto.'\',\''.$topic_id.'\',\''.$topic_cat.'\');return false;">Responder</a>
</div>';
}
}else{
$a_men=mysql_query("SELECT * FROM posts WHERE post_topic = '".$topic_id."' ")or die(mysql_error());
$numero_men=mysql_num_rows($a_men);
if($numero_men <= 1){
echo '<div class="totalmsj" ><div id="capa">No hay Comentarios.</div></div>';
}else{
$totalmsj = $numero_men-1;
echo '<div class="totalmsj" ><div id="capa"><strong style="color:black;">'.$totalmsj.' Comentarios</strong></div></div>';
}
}
?>
<?php
echo '<div class="clear"></div></div>';
}
// Output the comment, and its replies, if any
if(isset($arr['replies']))
{
foreach($arr['replies'] as $r)
showComment($r);
}
echo '</div>';
}]
Código PHP:
<?php
include 'functions.php';
$comments_result = mysql_query("SELECT posts.post_id,
posts.post_content,
posts.post_date,
users.user_id,
users.user_name,
users.foto_level,
users.user_ciudad,
users.user_foto,
users.foto_firma,
users.user_date,
users.user_level,
posts.cat_post,
posts.post_by,
posts.parent,
posts.usr,
posts.post_id,
posts.likes,
posts.hates
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
LEFT JOIN
categories
ON
posts.cat_post = categories.cat_id
WHERE
posts.post_topic = " . mysql_real_escape_string($_GET['temas'])." AND cat_post != 0 ORDER BY post_id");
$comments=array();
$js_history='';
while($row=mysql_fetch_assoc($comments_result))
{
if($row['parent']==0){
$comments directly
$comments[$row['post_id']] = $row;
}
else
{
if(!isset($comments[$row['parent']])) continue;
$comments[$row['parent']]['replies'][] = $row;
}
$js_history.='addHistory({id:"'.$row['post_id'].'"});'.PHP_EOL;
}
$js_history='<script type="text/javascript">
'.$js_history.'
</script>';
?>
Código PHP:
foreach($comments as $c)
{
showComment($c);
// Showing each comment
}
![Stress](http://static.forosdelweb.com/fdwtheme/images/smilies/stress.png)
![Stress](http://static.forosdelweb.com/fdwtheme/images/smilies/stress.png)
![Stress](http://static.forosdelweb.com/fdwtheme/images/smilies/stress.png)
![Stress](http://static.forosdelweb.com/fdwtheme/images/smilies/stress.png)
![Stress](http://static.forosdelweb.com/fdwtheme/images/smilies/stress.png)