1

Mi pregunta es como agregar los atributos colspan y rowspan html a php ya que estoy haciendo una tabla html en php porque necesito descargarla como un archivo.doc pero me genera error aquí:

 <?php
header("Content-type:application/vnd.ms-word");
header("Conten-Disposition:attachment;Filename=documento.doc");
echo "<html>";
echo "<meta http-equiv=\"content-Type\"content=\text\html;charset=utf-8\">";
echo"<body>";
echo "<br><br>Mi primer documento</br></br>";
echo "Aqu&iacute";
echo "<table>";
echo "<tr>";
echo "<td>imagen del sena</td>";
echo "<th><h2>FORMATO PARA PROTOCOLO DE DETERMINACION DE MOLIENDA F0205043</h2></th>";
echo "<th><h3>LABORATORIO DE ENSAYOS PARA EL MOBILIARIO </h3></th>";
echo "</tr>";
echo "<br>";
echo "<br>";
echo "<h3>Codigo de la Solicitud del servicio</h3>";
echo "<tr>";
echo "<th><h2>1.Informacion de la muestra</h2></th>";
echo "</tr>";
echo "<tr>";
echo "<td><h3>Fecha y Hora de Ejecucion del Ensayo</h3></td>";
echo "<td><h3>Tiempo dedicado a la Ejecucion del ensayo</h3></td>";
echo "<td><h3>Nombre de la Muestra</h3></td>";
echo "<td><h3>Tipo de Recubrimiento</h3></td>";
echo "<td><h3>Proporcion de Dilucion</h3></td>";
echo "<td><h3>Proporcion de catalizador o Endurecedor</h3></td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp</td>";
echo "<td>&nbsp</td>";
echo "<td>&nbsp</td>";
echo "<td>&nbsp</td>";
echo "<td>&nbsp</td>";
echo "<td>&nbsp</td>";
echo "<td>&nbsp</td>";
echo "</tr>";  
echo "<tr>";
echo "<th><h2>2.Planificacion del Ensayo</h2></th>";
echo "</tr>";
echo "<tr>";
echo "<td><h3>Norma o Procedimiento</h3></td>";
echo "<td><h3>Equipos Elementos e insumos utilizados</h3></td>";
echo "<td><h3>codigo</h3></td>";
echo "<td><h3>Equipos,elementos e insumos utilizados</h3></td>";
echo "<td><h3>Codigo</h3><td>";
echo "</tr>";
echo "<tr>";
echo "<td<h3>rowspan='4'>NTC 557 L0205007</h3></td>";
echo "<td><h3>Calibrador tipo hegman de dos pistas</h3></td>";
echo "<td><h3>&nbsp</h3></td>";
echo "<td><h3>Brocha</h3></td>";
echo "<td><h3>&nbsp</h3></td>";
echo "</tr>";
echo "<tr>";
echo "<td><h3>Reloj</h3></td>";
echo "<td><h3>&nbsp</h3></td>";
echo "<td><h3>Thinner</h3></td>";
echo "<td><h3>&nbsp</h3></td>";
echo "</tr>";
echo "<tr>";
echo "<td><h3>Espatula Mecanica</h3></td>";
echo "<td><h3>&nbsp</h3></td>";
echo "<td><h3>Estopa</h3></td>";
echo "<td><h3>&nbsp</h3></td>";
echo "</tr>";
echo "<tr>";
echo "<td><h3>Lampara</h3></td>";
echo "<td><h3>&nbsp</h3></td>";
echo "<td><h3>Beaker</h3></td>";
echo "<td><h3>&nbsp</h3></td>";
echo "</tr>";
echo "<tr>";
echo "<th><h2>RESULTADO DEL ENSAYO</h2></th>";
echo "<td><h3>Ensayo 1.</h3></td>";
echo "<td<h3>colspan='2'>&nbsp</h3></td>";
echo "<td<h3>rowspan='3'>Resultado promedio</h3></td>";
echo "</tr>";
echo "<tr>";
echo "<td><h3>Ensayo 2.</h3></td>";
echo "<td<h3>colspan='3'>Incertidumbre de la Aplicacion:No Aplica</h3></td>";
echo "</tr>";
echo "<tr>";
echo "<th><h3>4.VERIFICACION DE LOS RESULTADOS</h3></th>";
echo "<td><h3>Existen Errores</h3></td>";
echo "<td><h3>Si</h3></td>";
echo "<td><h3>No</h3></td>";
echo "<tr>";
echo "<td><h3>&nbsp</h3></td>";
echo "<td><h3>&nbsp</h3></td>";
echo "<td><h3>&nbsp</h3></td>";
echo "<td><h3>Describa los Errores encontrados</h3></td>";
echo "<td<h3>colspan='4'></h3></td>";
echo "</tr>";
echo "<tr>";
echo "<th><h2>5.OBSERVACIONES</h2></th>";
echo "<td<h2>colspan='5'>combine celdas horizontales</h2></td>";
echo "<td<h2>rowspan='3  '>combine celdas verticales</h2></td>";
echo "</tr>";
echo "</table>";
echo "</html>";
?>

POSSDATA:

Tuve que cambiar las comillas dobles por simples pero igualmente no toma los cambios que se supone he generado con colspan y rowspan.Podria alguien Ayudarme. Gracias

7
  • Hola bienvenido a Stack Overflow en español te sugiero que realices el recorrido de bienvenida y también leas Cómo preguntar, para que mejores tu pregunta, como tal tu pregunta es de baja calidad, también considera agregar un ejemplo mínimo verificable. Saludos
    – JuankGlezz
    el 31 may. 2017 a las 17:21
  • 1
    El error esta en la línea 23.
    – gbianchi
    el 31 may. 2017 a las 17:26
  • Puedes obtener el mismo resultado (o incluso mejor) sin usar tantos echo.
    – Alvaro Montoro
    el 1 jun. 2017 a las 0:24
  • Gracias pero continuo con el mismo problema sobre combinar celdas y filas en php con html; Ese es uno de los problemas; por ahi vi que concatenando se solucionaba pero aun no me funciona y no se por que :(
    – Grace
    el 1 jun. 2017 a las 20:26
  • echo "<td><h3>Describa los Errores encontrados:</h3></td>"; echo "<td colspan=\"3\"><h3>&nbsp</h3></td>"; echo "</tr>"; echo "<tr>"; echo "<th colspan=\"4\"><h2>5.OBSERVACIONES</h2></th>"; echo "</tr>"; echo "<tr>" ; echo "<td<h2>colspan=\"5\">&nbsp</h2></td>"; echo "<td<h2>rowspan=\"5\">&nbsp</h2></td>"; echo "</tr>"; echo "</table>"; echo "</html>"; ?>
    – Grace
    el 1 jun. 2017 a las 20:27

1 respuesta 1

2

Tú puedes mezclar código PHP/HTML en un archivo PHP sin problemas.

Ejemplo:

<html>
  <head>
    <title>Ejemplo de PHP con HTML</title>
  </head>
  <body>
    <h1>Encabezado 1</h1>
    <p>Este es un documento HTML creado en PHP</p>
    <?php
         //Aquí bloque de código PHP
    ?>
  </body>
     <table>
           <thead><tr><th>Encabezado1</th><th>Encabezado2</th></thead></tr>
                  <tr><td>Celda1</td><td>Celda2</td></tr>
     </table>
    <?php
         //Aquí otro bloque de código PHP
    ?>

</html>

Si por algún motivo tienes que construir toda una parte de HTML dentro de PHP, también puedes hacerlo.

Yo en esos casos creo una variable y voy concatenando los valores.

Ejemplo:

  $html="<table>";                
    $html.="<thead><tr><th>ENCABEZADO 1</th><th>ENCABEZADO 2</th></tr></thead>";
    $html.="<tbody>";

/*
    * Supongamos que estamos leyendo un conjunto de resultados
    * obtenidos de la base de datos
*/  

    while($data = mi_fetchassoc($stmt))
    { 
/*
    * Dentro del bucle, concatenamos cada valor en filas y celdas de la tabla
    * usando las etiquetas <tr> y <td>
    * Habrá un <td> por cada columna que querramos presentar en la tabla
    * Sustituye $data["...."] en cada td por los nombres de columna de tu tabla
*/  
        $html.="<tr>";
        $html.="<td>".$data["padre"]."</td>";
        $html.="<td>".$data["id_padre"]."</td>";
        $html.="</tr>";
    }

/*
    * Fuera del bucle, completamos nuestra variable $html 
    * Luego la imprimimos
*/  

    $html.="</tbody></table>";
    echo $html;

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.