Foros del Web » Programando para Internet » PHP »

Problema agregando HTML al codigo PHP

Estas en el tema de Problema agregando HTML al codigo PHP en el foro de PHP en Foros del Web. Hola, estoy haciendo un sistema de mensajes privados pero cuando le agrego el estilo tengo un problema, se desordena el css. Tengo un if que ...
  #1 (permalink)  
Antiguo 21/07/2012, 19:39
 
Fecha de Ingreso: julio-2010
Mensajes: 158
Antigüedad: 13 años, 9 meses
Puntos: 1
De acuerdo Problema agregando HTML al codigo PHP

Hola, estoy haciendo un sistema de mensajes privados pero cuando le agrego el estilo tengo un problema, se desordena el css.


Tengo un if que se fija si hay mensajes.

Código PHP:
if ($row==$cero) {
        echo("<center><b>No tienes mensajes.</b></center>");

    } else { 

echo' <table width="600" border="0" align="center" cellpadding="1" cellspacing="1">
    <tr>
      <td width="50" align="center" valign="top"><strong>Estado</strong></td>
      <td width="50" align="center" valign="top"><strong>De</strong></td>
      <td width="50" align="center" valign="top"><strong>Asunto</strong></td>
      <td width="50" align="center" valign="top"><strong>Fecha</strong></td>
      <td width="40" align="center" valign="top"><strong>Eliminar</strong></td>
    </tr>
    
    </tr>';
$i = 0; 
    while($row = mysql_fetch_assoc($res)){ ?>
      <tr bgcolor="<?php if($row['leido'] == "si") { echo "#FFCAB0"; } else { if($i%2==0) { echo "FFA07A"; } else { echo "FFA07A"; } } ?>">
   
      <td align="center" valign="top"><? if($row['leido'] == "si") { echo'<img src="leido.png" width="35" height="35" title= "Mensaje le&iacute;do"; alt="Mensaje le&iacute;do">'; } else { if($i%2==0) { echo'<img src="no-leido.png" width="35" height="35" title= "Mensaje NO le&iacute;do"; alt="Mensaje NO le&iacute;do">'; } else { echo'<img src="no-leido.png" width="35" height="35" alt="Mensaje NO le&iacute;do">'; } } ?></td>
      <td align="center" valign="top"><?=$row['de']?></td>
      <td align="center" valign="top"><a href="leer.php?id=<?=$row['ID']?>"><?=$row['asunto']?></a></td>
      <td align="center" valign="top"><?=$row['fecha']?></td>

 
<?php $i++; 
} } 
?>

ESTILO HTML
Cuando no hay mensajes muestra todo bien, cuando tens 1 o mas se mueve todo el estilo.
  #2 (permalink)  
Antiguo 21/07/2012, 20:02
Avatar de memoadian
Colaborador
 
Fecha de Ingreso: junio-2009
Ubicación: <?php echo 'México'?>
Mensajes: 3.696
Antigüedad: 14 años, 10 meses
Puntos: 641
Respuesta: Problema agregando HTML al codigo PHP

Seguramente que no es php el error.

pero bueno basta ver que tienes dos </tr> juntos sin ningún <tr> antes de repetirlos. antes del $i = 0

y desde ahí vamos mal.
  #3 (permalink)  
Antiguo 21/07/2012, 20:15
 
Fecha de Ingreso: julio-2010
Mensajes: 158
Antigüedad: 13 años, 9 meses
Puntos: 1
Respuesta: Problema agregando HTML al codigo PHP

Cita:
Iniciado por memoadian Ver Mensaje
Seguramente que no es php el error.

pero bueno basta ver que tienes dos </tr> juntos sin ningún <tr> antes de repetirlos. antes del $i = 0

y desde ahí vamos mal.
Ya lo saque, pero sigue igual.
  #4 (permalink)  
Antiguo 21/07/2012, 20:25
 
Fecha de Ingreso: octubre-2007
Mensajes: 39
Antigüedad: 16 años, 5 meses
Puntos: 1
Respuesta: Problema agregando HTML al codigo PHP

Cita:
Iniciado por ameno123 Ver Mensaje
Hola, estoy haciendo un sistema de mensajes privados pero cuando le agrego el estilo tengo un problema, se desordena el css.


Tengo un if que se fija si hay mensajes.

Código PHP:
if ($row==$cero) {
        echo("<center><b>No tienes mensajes.</b></center>");

    } else { 

echo' <table width="600" border="0" align="center" cellpadding="1" cellspacing="1">
    <tr>
      <td width="50" align="center" valign="top"><strong>Estado</strong></td>
      <td width="50" align="center" valign="top"><strong>De</strong></td>
      <td width="50" align="center" valign="top"><strong>Asunto</strong></td>
      <td width="50" align="center" valign="top"><strong>Fecha</strong></td>
      <td width="40" align="center" valign="top"><strong>Eliminar</strong></td>
    </tr>
    
    </tr>';
$i = 0; 
    while($row = mysql_fetch_assoc($res)){ ?>
      <tr bgcolor="<?php if($row['leido'] == "si") { echo "#FFCAB0"; } else { if($i%2==0) { echo "FFA07A"; } else { echo "FFA07A"; } } ?>">
   
      <td align="center" valign="top"><? if($row['leido'] == "si") { echo'<img src="leido.png" width="35" height="35" title= "Mensaje le&iacute;do"; alt="Mensaje le&iacute;do">'; } else { if($i%2==0) { echo'<img src="no-leido.png" width="35" height="35" title= "Mensaje NO le&iacute;do"; alt="Mensaje NO le&iacute;do">'; } else { echo'<img src="no-leido.png" width="35" height="35" alt="Mensaje NO le&iacute;do">'; } } ?></td>
      <td align="center" valign="top"><?=$row['de']?></td>
      <td align="center" valign="top"><a href="leer.php?id=<?=$row['ID']?>"><?=$row['asunto']?></a></td>
      <td align="center" valign="top"><?=$row['fecha']?></td>

 
<?php $i++; 
} } 
?>

ESTILO HTML
Cuando no hay mensajes muestra todo bien, cuando tens 1 o mas se mueve todo el estilo.
Me parece que falta cerrar la tabla </table>
  #5 (permalink)  
Antiguo 21/07/2012, 20:26
Avatar de memoadian
Colaborador
 
Fecha de Ingreso: junio-2009
Ubicación: <?php echo 'México'?>
Mensajes: 3.696
Antigüedad: 14 años, 10 meses
Puntos: 641
Respuesta: Problema agregando HTML al codigo PHP

Pues si por que seguramente tienes otros fallos. Revisa todo el código, no querrás que te lo revise como si fuera tu profesor.

Un consejo.

haz esto:
Código PHP:
Ver original
  1. <?php
  2. if ($row==$cero) {
  3. ?>
  4.     <center><b>No tienes mensajes.</b></center>
  5. <?php
  6.     } else {
  7. ?>
  8. <table width="600" border="0" align="center" cellpadding="1" cellspacing="1">
  9.     <tr>
  10.       <td width="50" align="center" valign="top"><strong>Estado</strong></td>
  11.       <td width="50" align="center" valign="top"><strong>De</strong></td>
  12.       <td width="50" align="center" valign="top"><strong>Asunto</strong></td>
  13.       <td width="50" align="center" valign="top"><strong>Fecha</strong></td>
  14.       <td width="40" align="center" valign="top"><strong>Eliminar</strong></td>
  15.     </tr>
  16. <?php
  17. }
  18. ?>

en lugar de lo que haces de poner todas las tablas en un echo. Así es más ordenado.
  #6 (permalink)  
Antiguo 21/07/2012, 23:46
Avatar de rodrigo791  
Fecha de Ingreso: noviembre-2009
Ubicación: Uruguay
Mensajes: 1.339
Antigüedad: 14 años, 5 meses
Puntos: 168
Respuesta: Problema agregando HTML al codigo PHP

Tampoco uses la forma corta de inicio de código php

Código PHP:
Ver original
  1. <?
  2.  
  3. ?>

usa esta
Código PHP:
Ver original
  1. <?php
  2.  
  3. ?>
  #7 (permalink)  
Antiguo 23/07/2012, 15:45
 
Fecha de Ingreso: julio-2010
Mensajes: 158
Antigüedad: 13 años, 9 meses
Puntos: 1
Respuesta: Problema agregando HTML al codigo PHP

Cita:
Iniciado por pablogross Ver Mensaje
Me parece que falta cerrar la tabla </table>

SOS UN GENIOOO!! Era eso.. GRACIAS!!

Gracias a los demás también.

Le puse un

Código HTML:
</table> 
Después de
Código PHP:
} } ?> 

Última edición por ameno123; 23/07/2012 a las 17:13

Etiquetas: html, mysql
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 23:44.