Foros del Web » Programando para Internet » PHP »

Los mensajes en bandeja de entrada salen dobles

Estas en el tema de Los mensajes en bandeja de entrada salen dobles en el foro de PHP en Foros del Web. Tengo el siguiente codigo PHP para la bandeja de entrada de los usuarios: Código PHP: <?php // conexion ?> <?php if (! function_exists ( "GetSQLValueString" )) { function  ...
  #1 (permalink)  
Antiguo 25/03/2011, 12:23
 
Fecha de Ingreso: julio-2006
Mensajes: 254
Antigüedad: 17 años, 9 meses
Puntos: 0
Los mensajes en bandeja de entrada salen dobles

Tengo el siguiente codigo PHP para la bandeja de entrada de los usuarios:
Código PHP:
<?php
// conexion
?>
<?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;
}
}

$colname_mensajes "-1";
if (isset(
$_COOKIE['usuario'])) {
  
$colname_mensajes $_COOKIE['usuario'];
}
mysql_select_db($database_general$general);
$query_mensajes sprintf("SELECT * FROM mensajes WHERE para = %s ORDER BY id DESC"GetSQLValueString($colname_mensajes"text"));
$mensajes mysql_query($query_mensajes$general) or die(mysql_error());
$row_mensajes mysql_fetch_assoc($mensajes);
$totalRows_mensajes mysql_num_rows($mensajes);


?>
<?php
$mensajes 
mysql_query("SELECT * FROM mensajes WHERE para = '$_COOKIE[usuario]'");
$mensajesnuevos mysql_query("SELECT * FROM mensajes WHERE para = '$_COOKIE[usuario]' && leido = 'no'");
$filasmensajes mysql_num_rows($mensajes);
$filasmensajesnuevos mysql_num_rows($mensajesnuevos);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<style type="text/css">
.centro {
    text-align: center;
}

</style>
</head>

<body class="centro">
<p><a href="/index.php?cont=amigos-md.php">Bandeja de Entrada</a> - <a href="/index.php?cont=amigos-md-enviar.php">Enviar un mensaje</a></p>
<p>Tienes <? echo"$filasmensajes"?> mensajes en tu bandeja de entrada.</p>
<p>Tienes <? echo"$filasmensajesnuevos"?> mensajes sin leer.</p>
<p>&nbsp;</p>
<table border="0" align="center" cellspacing="1">
  <tr>
      <td bgcolor="#666666">&nbsp;</td>
         <td bgcolor="#666666">#</td>
         <td bgcolor="#666666">Fecha</td>
    <td bgcolor="#666666">Enviado por</td>

 
    
    <td bgcolor="#666666">Asunto</td>
  </tr>
  <?php do { ?>
    <tr>
    <td bgcolor="#666666"><?php echo $row_mensajes['leido']; ?></td>
     <td bgcolor="#666666"><?php echo $row_mensajes['id']; ?></td>
         <td bgcolor="#666666"><?php echo $row_mensajes['fecha']; ?></td>
      <td bgcolor="#666666"><?php echo $row_mensajes['de']; ?></td>
      
     
  
      <td bgcolor="#666666"><p><?php echo $row_mensajes['asunto']; ?></p></td>
    </tr>
    <?php } while ($row_mensajes mysql_fetch_assoc($mensajes)); ?>
</table>
<p>-Ayuda-</p>
<p>-Para leer un mensaje, haz clic sobre su Asunto.</p>
<p>-Los mensajes se ordenan por fecha de envío.</p>
<p>-Cuando aún no hayas leído un mensaje, la primera columna del correo aparecerá blanca.</p>
<p>-Cuando llegues a 100 mensajes, automaticamente se te borrarán todos los mensajes. Por eso, procura ir borrando los mensajes que no desees guardar, haciendo clic en la cruz que aparecera a la derecha del mensaje.</p>
<p>-Si quieres guardar más de 100 mensajes, puedes pedir una solicitud de aumento.</p>
</body>
</html>
<?php
mysql_free_result
($mensajes);
?>
El asunto es que , yo inserté en mi BD un mensaje,
y cuando entro a la bandeja de entrada, aparece, pero DOBLE. Osea, aparecen DOS mensajes iguales..
Porque??
Gracias!

PD.: Agregé otro mensaje a la BD , y ahora me sale:


El primer mensaje: BIEN
El segundo mensaje: DOBLE.



Cita:
Lo solucioné cambiando el DO WHILE por un simple WHILE
Pero ahora el problema es que el orden no aparece DESCENDIENDO sino ASCENDIENDO...
:s

Última edición por lauchalp95; 25/03/2011 a las 13:01
  #2 (permalink)  
Antiguo 25/03/2011, 13:34
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Los mensajes en bandeja de entrada salen dobles

puedes cambiar el orden de la consulta...
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 25/03/2011, 14:35
 
Fecha de Ingreso: julio-2006
Mensajes: 254
Antigüedad: 17 años, 9 meses
Puntos: 0
Respuesta: Los mensajes en bandeja de entrada salen dobles

Hola..
Suponiendo que la consulta es
Código MySQL:
Ver original
  1. SELECT * FROM mensajes WHERE para = &#37;s ORDER BY id DESC

Así debería estar bien!!
(Osea, se debería ver: 3,2,1; sin embargo se ve 1,2,3)


Listo, lo solucioné!

Etiquetas: bandeja, dobles, entrada, mensajes
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:39.