Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
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

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

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";
over 4 years ago · Santiago Trujillo Relatório

0

Thank you very much for this help, i have been fixed!!

here is the code that i fixed, with your idea :)

´´´´

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

´´´´

Table with these columns that fixed by this code php

over 4 years ago · Santiago Trujillo Relatório

0

Like Riggsfolly said but maybe divide the columns number by 2 before the modulo, because there are 2 TDs / iteration:

if ( $i % ($columnas/2) ) == 0 ) {
    print "</tr><tr>\n";
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda