Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/06/2010, 23:32
L4NS
 
Fecha de Ingreso: mayo-2010
Mensajes: 99
Antigüedad: 14 años
Puntos: 1
Pregunta como relacionar para mostrar solo los comentarios de id una foto?

AYUDAAA amigos este es mi problema:

tengo un sistema de fotos en mi web para subir fotos, y cuando suben la foto atomaticamente abajo aparece para comentar, todo va bien, el problema es que aparece para comentar, pero aparece los comentarios que se han hecho en todas las fotos es decir no aparecen nada mas lo comentarios de la foto que se esta comentando.

la base de datos ya esta relacionada en LA TABLA comentarios con fotos_ID el problema es que no se hacer el script q me muestre solo el comentario en la foto que comente y no me aparesca en otras fotos el comentario de esta...espero me entiendan, estos son mis scripts:

el formulario del comentario(comentarios.php)
Código PHP:
<?php
session_start
();
?>
<?php 
//Conectamos a la Base de datos
require_once('Connections/xtremebook.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']);
}

//seleccionamos la BD

mysql_select_db($database_xtreme_book$xtremebook);
$query_Recordset1 "SELECT  NOMBRE, APELLIDO FROM registro";
$Recordset1 mysql_query($query_Recordset1$xtremebook) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

$maxRows_tabla_alumnos 10;
$pageNum_tabla_alumnos 0;
if (isset(
$_GET['pageNum_tabla_alumnos'])) {
  
$pageNum_tabla_alumnos $_GET['pageNum_tabla_alumnos'];
}
$startRow_tabla_alumnos $pageNum_tabla_alumnos $maxRows_tabla_alumnos;

mysql_select_db($database_xtreme_book$xtremebook);
$query_tabla_alumnos "SELECT  NOMBRE, APELLIDO, NOMBREUSUARIO, CONTRASENA, EMAIL, SEXO FROM registro";
$query_limit_tabla_alumnos sprintf("%s LIMIT %d, %d"$query_tabla_alumnos$startRow_tabla_alumnos$maxRows_tabla_alumnos);
$tabla_alumnos mysql_query($query_limit_tabla_alumnos$xtremebook) or die(mysql_error());
$row_tabla_alumnos mysql_fetch_assoc($tabla_alumnos);

if (isset(
$_GET['totalRows_tabla_alumnos'])) {
  
$totalRows_tabla_alumnos $_GET['totalRows_tabla_alumnos'];
} else {
  
$all_tabla_alumnos mysql_query($query_tabla_alumnos);
  
$totalRows_tabla_alumnos mysql_num_rows($all_tabla_alumnos);
}
$totalPages_tabla_alumnos ceil($totalRows_tabla_alumnos/$maxRows_tabla_alumnos)-1;
?>
<form id="form1" name="form1" method="post" action="Ecomentario.php" onSubmit="return verifica()">
  <table width="300" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
    <tr>
      <td bgcolor="#33CCFF"colspan="2"><div align="center" class="style30 style44"><b>Comentarios</b></div></td>
    </tr>
    <tr>
      <td bgcolor="#D8EFFA" width="71"><? 
        
include('login.php');
echo 
"<b><font color='#3399FF'>".$_SESSION['MM_Username'];
?></b>
        dice:</td>
      <td bgcolor="#D8EFFA" width="161"><span class="style29">
        <label></label>
        <textarea name="COMENTARIO[<?php echo $datos['ID']; ?>]"></textarea>
      </span></td>
    </tr>
    <tr>
      <td bgcolor="#D8EFFA" colspan="2"><b>
        <div align="right">
          <input     style="background-color:#33CCFF; font:bold;  "type="submit" name="Submit" value="Comentar" />
        </div>
      </b></td>
    </tr>
  </table>
</form>
<br /><table align="center" bgcolor="#D8EFFA" width="300" border="0" cellspacing="5">
  <tr>
    <th scope="row"><div align="left"><?php
    mysql_connect
("localhost","root","1234") or die ("no se ha podido conectar a la BD");

    
mysql_select_db("xtremebook") or die ("no se ha podido seleccionar la BD");

    
$sql "SELECT ID,COMENTARIO,FECHA,HORA FROM comentarios";
    
$consulta mysql_query($sql) or die ("No se pudo ejecutar la consulta");

    While (
$registro=mysql_fetch_assoc($consulta)){
        echo 
"<br><br> Comentario: ".$registro['COMENTARIO']."<BR>hecho el:<br>".$registro['FECHA']."<BR> a las ".$registro['HORA'];
    }

?> </div></th>
  </tr>
  <tr>
    <th scope="row"><div align="left">
     </div></th>
  </tr>
</table>
el insertar en la base de datos del formulario comentario(Ecomentarios.php)

Código PHP:
<?php
/*
                                ________________________________________________________________________
                                |:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
                                |:::PROGRAMACION DEL SISTEMA INSERTAR DATOS EN BD  POR ENMANUEL DURAN:::|  
                                |:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
                                -------------------------------------------------------------------------
*/
    // Primero comprobamos que ningún campo esté vacío y que todos los campos existan.
    
$fecha=date("j-n-Y");
    
$hora=date("h:i:s");
    if(isset(
$_POST['COMENTARIO']) && !empty($_POST['COMENTARIO'])) {


        
// Si entramos es que todo se ha realizado correctamente

        
$link mysql_connect("localhost","root","1234");
        
mysql_select_db("xtremebook",$link);

        
// Con esta sentencia SQL insertaremos los datos en la base de datos
        
mysql_query("INSERT INTO comentarios (COMENTARIO,FECHA,HORA)
        VALUES ('{$_POST['COMENTARIO']}','$fecha','$hora')"
,$link);

        
// Ahora comprobaremos que todo ha ido correctamente
        
$my_error mysql_error($link);

        if(!empty(
$my_error)) {

            echo 
"Ha habido un error al insertar los valores. $my_error";

        } else {

           echo 
"<script type=\"text/javascript\">alert('Se Ha Registrado Exitosamente');
        location.href='javascript:history.go(-1)'; </script>"
;

        }

    } else {

        echo 
"<script type=\"text/javascript\">alert('Ocurrio Un Error Usted No Introdujo Todos Los Datos Debe Volver Atras');
        location.href='javascript:history.go(-1)'; </script>"
;

    }

?>

</body>
</html>
el script para mostrar las imagenes paginadas y el sistema de comentario debajo de ellas pero con el problema mencionado(listar_imagenes.php):

Código PHP:
<?php
session_start
();
?>

<?php

require_once 'PHPPaging.lib.php';

$paging = new PHPPaging


   
// Abrimos la conexión al servidor MySQL
$link mysql_connect('localhost''root''1234');
mysql_select_db('xtremebook'$link);


// Instanciamos, indicando el recurso de conexión
$paging = new PHPPaging($link);


$q "SELECT * FROM fotos ORDER BY id DESC";

// Y se usa la función agregarConsulta() (Ver documentación)
$paging->agregarConsulta($q);  

$paging->ejecutar();

  while(
$datos $paging->fetchResultado()) { 
    
// En cada ciclo, la variable $datos se convierte en un arreglo
    // que contiene los datos de la fila que corresponde
    
echo "<img src =\"ver.php?ID=".$datos['ID']."\"width='500' height='500'><br>";
    echo 
"Nombre:" $datos['NOMBRE'] . "<br />";
    echo 
"Apellidos:" $datos['TIPO'] . "<br />";
    echo 
"País:" $datos['PESO'] . "<br />";
    echo 
"<br />";
include(
'comentarios.php');
}
//Una cadena conteniendo el codigo HTML de la barra de 
//navagación es generada y guardada en la variable $links.
$links $paging->fetchNavegacion();

echo 
$links;
    
?>
Gracias de antemano les doy de verdad disculpen la molestia, les estare muy agradecidos si me ayudan!