Foros del Web » Programando para Internet » PHP »

Imprimir consulta sql en php con una tabla

Estas en el tema de Imprimir consulta sql en php con una tabla en el foro de PHP en Foros del Web. Código PHP: ?> <table cellpadding="0" cellspacing="0" width="751" height="169">      <?                         $resulttag  =  mysql_query ( 'SELECT * FROM tags WHERE id_usuario=\'' . $idrow . '\'' );                             while ( $tagg  =  mysql_fetch_row ( $resulttag )){                             echo  ...
  #1 (permalink)  
Antiguo 22/01/2012, 09:17
 
Fecha de Ingreso: junio-2009
Mensajes: 80
Antigüedad: 14 años, 9 meses
Puntos: 2
Pregunta Imprimir consulta sql en php con una tabla

Código PHP:
?>
<table cellpadding="0" cellspacing="0" width="751" height="169">
    



<?
                        $resulttag 
mysql_query('SELECT * FROM tags WHERE id_usuario=\''.$idrow.'\'');
   
                        while (
$tagg mysql_fetch_row($resulttag)){

                            echo 
"<tr>";
                            echo 
"<td valign='middle' height='130' background='colortags/" $tagg[2] . ".png'>" $tagg[3] . "</td>";
                                echo 
"<td>&nbsp;</td>";
                            echo 
"</tr>";
                            echo 
"<tr>";
                            echo
"    <td width='357'>&nbsp;</td>
                                <td width='37'>&nbsp;</td>
                                <td height='39' width='357'>&nbsp;</td>
                            </tr>"
;
    
                                }
?>

</table>
Esta consulta tal y como la ven... daría un resultado así:




Pero necesito otra cosa... Necesito que el resultado sea así:



He intentado con:

Código PHP:
?>
<table cellpadding="0" cellspacing="0" width="751" height="169">
    



<?
                        $resulttag 
mysql_query('SELECT * FROM tags WHERE id_usuario=\''.$idrow.'\'');
   
                        while (
$tagg mysql_fetch_row($resulttag)){

                            echo 
"<tr>";
                            echo 
"<td valign='middle' height='130' background='colortags/" $tagg[2] . ".png'>" $tagg[3] . "</td>";
                                echo 
"<td>&nbsp;</td>";
                            echo 
"<td valign='middle' height='130' background='colortags/" $tagg[2] . ".png'>" $tagg[3] . "</td>";

                            echo 
"</tr>";
                            echo 
"<tr>";
                            echo
"    <td width='357'>&nbsp;</td>
                                <td width='37'>&nbsp;</td>
                                <td height='39' width='357'>&nbsp;</td>
                            </tr>"
;
    
                                }
?>

</table>

Pero el resultado es:


Alguien sabe como podría hacer lo que necesito? Estoy atascado en este punto y no se continuar :(

Última edición por quiquebg; 22/01/2012 a las 12:48
  #2 (permalink)  
Antiguo 23/01/2012, 12:31
Avatar de linuxzero  
Fecha de Ingreso: noviembre-2011
Ubicación: Argentina
Mensajes: 778
Antigüedad: 12 años, 5 meses
Puntos: 160
Respuesta: Imprimir consulta sql en php con una tabla

Podes probar asi:

Código PHP:
Ver original
  1. <table cellpadding="0" cellspacing="0" width="751" height="169">
  2.  
  3. <?
  4.         $resulttag = mysql_query('SELECT * FROM tags WHERE id_usuario=\''.$idrow.'\'');
  5.         $i = 0;
  6.         while ($tagg = mysql_fetch_row($resulttag)){
  7.                
  8.                 // Si es impar, empiezo fila
  9.                 if ($i % 2 != 0) {
  10.                        echo "<tr>";
  11.                        echo "<td valign='middle' height='130' background='colortags/" . $tagg[2] . ".png'>" . $tagg[3] . "</td>";            
  12.                  } else {
  13.                        // Si es par, agrego columna par y cierro fila
  14.                        echo "<td valign='middle' height='130' background='colortags/" . $tagg[2] . ".png'>" .
  15.                        echo "</tr>";
  16.                        echo "<tr>";
  17.                        echo"<td width='357'>&nbsp;</td>
  18.                                 <td width='37'>&nbsp;</td>
  19.                                 <td height='39' width='357'>&nbsp;</td></tr>";
  20.                   }
  21.                   $i++;              
  22.          }
  23. ?>
  24.  
  25. </table>
__________________
Si todo fuera tan sencillo como un symfony cc la vida seria más fácil.
http://phpnico.wordpress.com
  #3 (permalink)  
Antiguo 24/01/2012, 11:24
 
Fecha de Ingreso: junio-2009
Mensajes: 80
Antigüedad: 14 años, 9 meses
Puntos: 2
Respuesta: Imprimir consulta sql en php con una tabla

Gracias! me funciono a la perfección!

Te debo una ;)
  #4 (permalink)  
Antiguo 24/01/2012, 12:01
Avatar de linuxzero  
Fecha de Ingreso: noviembre-2011
Ubicación: Argentina
Mensajes: 778
Antigüedad: 12 años, 5 meses
Puntos: 160
Respuesta: Imprimir consulta sql en php con una tabla

Cita:
Iniciado por quiquebg Ver Mensaje
Gracias! me funciono a la perfección!

Te debo una ;)
De nada campeon, me alegro que te haya funcionado ;)
__________________
Si todo fuera tan sencillo como un symfony cc la vida seria más fácil.
http://phpnico.wordpress.com

Etiquetas: tablas
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 12:57.