Bienvenido a datoweb.com!! En este foro podrás encontrar ayuda sobre diseño y desarrollo web en general. Si quieres formar parte de esta comunidad para pedir ayuda o colaborar ayudando a otros usuarios del foro solo tienes que registrarte desde el siguiente enlace: Registrarse en el Foro

Ayuda con Comentarios Anidados en php y mysql

Hola a todos bueno queria ver si me puden ayudar a poner comentarios anidados en mi web en php a que me refiero con comentarios anidados pues que los usuarios puedan responder un comentario creado por otro.
asi como se ven en la imagen del comentario lo que quiero es hacer valer la opcion de responder que se muestran en la siguiente imagen.

les mostrare el codigo que e creado espero que me digan que puedo añadirle para habilitar la opcion de responder.
<div id="listadocomment">
<div class="cotitulo"><img src="../img/060.png"><span><?php echo $totalRows_vercomentarios ?> Comentarios</span></div>
<div class="comentarios_warning">Los comentarios que contengan: spam, spoiler, o anuncien su número de comentario (primero, segundo, etc) serán eliminados.</div>
<?php do { ?>
<?php if ($totalRows_vercomentarios > 0) { // Show if recordset not empty ?>

<div id="listado">
<div id="comment">
<div id="avatar-image-container">
<img src="<?php echo avatar($row_vercomentarios['id_user']) ?>"/></div>
<div class="comment-block">
<span class="dialog"></span>
<div class="comment-header"><?php echo nombre($row_vercomentarios['id_user']); ?><span style="color:#06F"> Dijo:</div>
<?php echo $row_vercomentarios['comentario']; ?>
<span class="comment-actions">
<span class="datetime"><?php echo $row_vercomentarios['fecha']; ?></span>
<?php if ((isset($_SESSION['MM_Username']))&& ($_SESSION['MM_Username']!=""))
{ ?>
<a id="<?php echo $row_vercomentarios['id_comment']; ?>" href="#form1" class='reply' style="cursor:pointer;">Responder</a>
<?php }else{?>
<a href="#" title="Debes Iniciar Sesion para poder responder">Responder</a>
<?php }?>
</span>
</div>
</div>

</div>
<?php } ?>
<?php if ($totalRows_vercomentarios == 0) { // Show if recordset empty ?>
<center><span style="text-shadow: 1px 1px 1px #ccc;font-weight: bold;">No existe ningun comentario para este Post se el primero</span></center>
<?php } // Show if recordset empty ?>
<?php } while ($row_vercomentarios = mysql_fetch_assoc($vercomentarios)); ?>
<?php mysql_free_result($vercomentarios);	?>
</div>

<?php if ((isset($_SESSION['MM_Username']))&& ($_SESSION['MM_Username']!=""))
{ ?>
<div id="comment">
<form action="<?php echo $urlWeb ?>includes/comentar.php" method="post" name="form1" id="form1">
<div id="editorcomment">
  <textarea id="textarea-1" name="comentario"  rows="4" placeholder="Comentar.."></textarea>
     <script type="text/javascript">
	CKEDITOR.replace ("textarea-1");
	</script></div>
<input class="boton_login" type="submit" value="Comentar" />
  <input type="hidden" name="id_user" value="<?php echo $_SESSION['MM_Id']; ?>" />
  <input type="hidden" name="id_post" value="<?php echo $row_SacarPostGet['id']; ?>" />	 
  <input type="hidden" name="MM_insert" value="form1" />
</form>
</div>
<?php }
else
{?>
<center><span style="text-shadow: 1px 1px 1px #ccc;font-weight: bold;">Nesecitas <a href="../user/login.php">Iniciar Sesion</a> o estar <a href="../user/registro.php">registrado</a> para comentar</span></center>
<?php }?>
ahora el codigo de comentar.php
<?php require_once('../Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO d_comment (parent_id, id_user, id_post, comentario) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['id_user'], "int"),
                       GetSQLValueString($_POST['id_post'], "int"),
                       GetSQLValueString($_POST['comentario'], "text"));

  mysql_select_db($database_conexion, $conexion);
  $Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());

  $insertGoTo = $_SERVER['HTTP_REFERER'];
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
eso es todo gracias de antemano.
0
Puntos
4803
Visitas
3
Resp
Por Codewar hace 126 meses
Principiante
Respuesta #1
Me habia olvidado aqui la imagen de mi tabla.


0
Puntos
Por Codewar hace 126 meses
Principiante
Respuesta #2
Esto es lo que yo haría codewar. Crearía otra tabla para los comentarios de comentarios. Y haría lo mismo como si fuese para un post. Lo que cambia es que en vez de colocar en la tabla id_post colocaría id_comentario Ya que esa respuesta va referenciada hacia un comentario. ¿Me entiendes? Lo demás lo deberías saber ya que es lo mismo como si fueses a comentar un post. Cualquier cosa, aquí estamos !!
0
Puntos
Por Jose hace 126 meses
Experto Sitio web
Respuesta #3
Encontre la respuesta http://www.jgdprojects.co.uk/codingcomments.htm aqui les dejo el enlace por si alguien quiere implementar la opcion de responder :)
0
Puntos
Por Codewar hace 126 meses
Principiante
Compartir en facebook
Compartir en twitter
Compartir
Para comentar Inicia sesión o Registrate