Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/01/2013, 14:58
Avatar de franco9090
franco9090
 
Fecha de Ingreso: diciembre-2012
Ubicación: Medellin
Mensajes: 10
Antigüedad: 11 años, 4 meses
Puntos: 0
Mensaje Hacer que un Sistema de Comentarios sea para Varias Paginas

Tengo un pequeño problema. He buscado la solución en el foro y en la web y creo que estoy haciendo lo correcto pero hace falta algo, y me gustaría que alguno me pudiera ayudar con ello si es posible.

tengo las siguientes paginas:

Pagina_ventas.php

pagina_muestras.php

blog_clientes.php

He descargado un sistema de comentarios muy chulo pero que solo trabaja con una pagina, es decir, si yo lo incluyera en esas tres paginas saldrían los mismos comentarios en las tres.
El sistema de comentarios tiene los siguientes archivos:

comentarios.php //Contiene el form y muestra los comentarios que se van añadiendo.


Código PHP:
<?php
$id_of_page 
1;
// Error reporting:
error_reporting(E_ALL^E_NOTICE);

include 
"comentarios/connect.php";
include 
"comentarios/comentarios.clase.php";


/*
/    Select all the comments and populate the $comments array with objects
*/

$comments = array();
$result mysql_query("SELECT * FROM comments WHERE id_page=".$id_of_page." ORDER BY id ASC");

while(
$row mysql_fetch_assoc($result))
{
    
$comments[] = new Comment($row);
}

?>


<link rel="stylesheet" type="text/css" href="<?php echo BASE_URL?>comentarios/styles.css" />





<?php

/*
/    Output the comments one by one:
*/

foreach($comments as $c){
    echo 
$c->markup();
}

?>

<div id="addCommentContainer">
    <p>Agrega un Comentario</p>
    <form id="addCommentForm" method="post" action="">
        <div>
            <label for="name">Tu Nombre</label>
            <input type="text" name="name" id="name" />
            
            <label for="email">Tu Email</label>
            <input type="text" name="email" id="email" />
            
            <label for="url">Sitio Web (No obligatorio)</label>
            <input type="text" name="url" id="url" />
            
            <label for="body">Comentario o Mensaje</label>
            <textarea name="body" id="body" cols="20" rows="5"></textarea>
            
            <input type="hidden" name="id_page" id="id_page" value="<?php echo $id_of_page?>" />
            
            <input type="submit" id="submit" value="Enviar" />
        </div>
    </form>
</div>



<script type="text/javascript" src="<?php echo BASE_URL?>comentarios/script.js"></script>

submit.php // Envía la información a la base de datos.

Código PHP:
<?php


// Error reporting:
error_reporting(E_ALL^E_NOTICE);

include 
"connect.php";
include 
"comentarios.clase.php";


/*
/    This array is going to be populated with either
/    the data that was sent to the script, or the
/    error messages.
/*/

$arr = array();
$validates Comment::validate($arr);

if(
$validates)
{
    
/* Everything is OK, insert to database: */
    
    
mysql_query("    INSERT INTO comments(name,url,email,body,id_page)
                    VALUES (
                        '"
.$arr['name']."',
                        '"
.$arr['url']."',
                        '"
.$arr['email']."',
                        '"
.$arr['body']."',
                        '"
.$id_of_page."'
                    )"
);
    
    
$arr['dt'] = date('r',time());
    
$arr['id'] = mysql_insert_id();
    
    
/*
    /    The data in $arr is escaped for the mysql query,
    /    but we need the unescaped variables, so we apply,
    /    stripslashes to all the elements in the array:
    /*/
    
    
$arr array_map('stripslashes',$arr);
    
    
$insertedComment = new Comment($arr);

    
/* Outputting the markup of the just-inserted comment: */

    
echo json_encode(array('status'=>1,'html'=>$insertedComment->markup()));

}
else
{
    
/* Outputtng the error messages */
    
echo '{"status":0,"errors":'.json_encode($arr).'}';
}

?>
Como pueden ver lo que hice fue hacer un identificador a cada pagina donde quiero que salgan comentarios de la siguiente manera :
Código PHP:
$id_of_page 1;
$id_of_page 2
y asi sucesivamente.
Luego en la base de datos añadí un nuevo campo que se llama id_page y cambié la consulta en comentarios.php asi:

Código PHP:
$comments = array();
$result mysql_query("SELECT * FROM comments WHERE id_page=".$id_of_page." ORDER BY id ASC"); 
En el form agregue el nuevo valor asi:

Código PHP:
<input type="hidden" name="id_page" id="id_page" value="<?php echo $id_of_page?>" />
Y finalmente en submit.php, agregue el campo en el INSERT asi:

Código PHP:
mysql_query("    INSERT INTO comments(name,url,email,body,id_page)
                    VALUES (
                        '"
.$arr['name']."',
                        '"
.$arr['url']."',
                        '"
.$arr['email']."',
                        '"
.$arr['body']."',
                        '"
.$id_of_page."'
                    )"
);
    
    
$arr['dt'] = date('r',time());
    
$arr['id'] = mysql_insert_id(); 
En mi novato concepto esto ya debería funcionar, pero bien dicho soy novato.
Así que no me están llegando los valores de las variables a la base datos y por ende al refrescar la pagina se borran los comentarios, ya que quedan con valor '0' en el campo id_page en la tabla.

Se que algo muy pequeño esta faltándome para que todo trabaje bien, pero aun no descubro que es .
Encima luego debo lograr que cada noticia nueva en blog_clientes.php tenga sus propios comentarios.
Les agradecería enormemente si alguno me puede orientar.
Un Saludo.

Última edición por franco9090; 02/01/2013 a las 17:27