Search code examples
phpphp-7.4

How to break a column to fix a php table


I had a little problem, i cannot break the table because I'm looking for a 16 columns in these table to create a unicode table... The aim is to find where i must break the line of the column as like as there:

<?php 

$columnas = 16;
$filas = 16;
$word= 0;
$contador = 0;

print "<table border=\"1\">\n";
print "<caption>ASCII</caption>\n";
print "<tbody>\n";
print "<tr>\n";

for ($j = 1; $j <= $columnas; $j++){
    if ($j%2 == 1){
        print "<th>Codigo</th>\n";
    }elseif ($j%2 == 0){
         print "<th>Valor</th>\n";
    }
}
print "</tr>";

for ($i = 1; $i <= $filas; $i++){

    for($i = 1; $i <= 50000; $i++,$contador){
        $unicodeChar = "&#{$i}";
        $contador--;
        print "<td>" .$i. "</td>\n";
        print "<td>".$unicodeChar."</td> \n";
    }   
    print "</tr>\n";
}   

print "</tbody>\n";
print "</table>\n";
 
?>

enter image description here


Solution

  • You used the modulus in the first loop, so use it again in the second

    print "</tr>";
    
    print "<tr>";
    for($i = 1; $i <= 50000; $i++){
        $unicodeChar = "&#{$i}";
        $contador--;
        print "<td>$i</td><td>$unicodeChar</td>\n";
    
        if ( $i % $columnas/2 ) == 0 ) {
            print "</tr><tr>\n";
        }
    }   
    print "</tr>\n";