Hello this is my code and even though I set the rowspan to 3 it doesn't generate the table correctly, I try to generate a table from a two-dimensional array with PHP but when I format the table it doesn't work as it should, I can't find the error, please help.
<table border="1">
<?php
//Primero creamos dos arrays $matriz_pablo y $matriz_roberto para luego insertarlas en un array general $matriz_general la que sera bidimensional
$matriz_pablo = array('nombre' => 'pablo', 'profesion' => 'ministro', 'edad' => '50');
$matriz_roberto = array('nombre' => 'roberto', 'profesion' => 'agricultor', 'edad' => '45');
$matriz_general = array('PABLO' => $matriz_pablo,'ROBERTO' => $matriz_roberto);
//A continuación imprimimos los valores de la matriz bidimensional.
//El Primer FOREACH muestra las claves de primer nivel PABLO y ROBERTO
foreach ($matriz_general as $key => $value) {
echo "<tr>"."<td rowspan='3'>".$key."</td>";//Se muetra la Clave
//El Segundo FOREACH mostrará las claves y valores de segundo nivel internos de la columna valor de primer nivel.
foreach ($value as $clave => $valor) {
echo "<tr>"."<td>".$clave."</td>"."<td>".$valor."</td>"."</tr>";
}
echo "</tr>";
}
?>
</table>
If you expect a table like this in result:
You have to change
to this:echo "<tr>"."<td rowspan='3'>".$key."</td>";
echo "<tr>"."<td rowspan='4'>".$key."</td>";
, because it's 4 rows you want to join, not 3.Or, come up with another way to create the table.
I was parsing the code and I think I managed to solve it with rowspan = "3" removing one of the tags and lowering the td one level