如何拆分列以修复 php table

How to break a column to fix a php table

我遇到了一个小问题,我无法破解 table,因为我正在寻找这些 table 中的 16 列来创建一个 unicode table... 目的是找到我必须在哪里打破列的线,就像那里一样:

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

你在第一个循环中使用了模数,所以在第二个循环中再次使用它

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

非常感谢您的帮助,我已经修好了!!

这是我根据您的想法修复的代码:)

´´´´

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

            if (($i % 8 ) == 0 ){
                print "</tr><tr>";
            }
        }   
        print "</tr>\n";
    }
    

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

´´´´

Riggsfolly所说,但可能在模数之前将列数除以 2,因为有 2 个 TD/迭代:

if ( $i % ($columnas/2) ) == 0 ) {
    print "</tr><tr>\n";
}