How to generate a table with rowspan and colspan in php

1

My question is how to add the colspan and rowspan html attributes to php since I am making an html table in php because I need to download it as a .doc file but it generates an error here:

 <?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:

I had to change the double quotes for simple but it also does not take the changes that I'm supposed to have generated with colspan and rowspan. Could someone help me. Thanks

    
asked by Grace 31.05.2017 в 19:13
source

1 answer

1

You can mix PHP / HTML code in a PHP file without problems.

Example:

<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>

If for some reason you have to build a whole part of HTML within PHP, you can also do it.

In those cases I create a variable and I concatenate the values.

Example:

  $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;
    
answered by 31.05.2017 в 19:33