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
Hi, I am new to php and I cant find a way to make alternate table color in my code. It always show the wrong output that is required for me to follow

I did the nth child rule in css but it the colors are not alternate. Colors are all the same each rows and columns. My code is a multiplication table with a supposed alternate color. Im having a hard time knowing what I should do to modify or add in my php code to create the desired output (alternate colors in rows and columns in the multiplication table).

Below is my php code:

<?php
    for($row=0; $row<=10; $row++){
        echo "<tr>";
        
        for($column=0; $column<=10; $column++){

            if($row==0 && $column==0){
                echo "<td></td>";
            }
                
            else{
                echo "<td>". $row * $column. "</td>";
            }
            
        }
    }
    echo "</tr>";
    ?>

CSS code:

table, th, td {
    border: 1px solid black;
}

td {
    padding: 15px;
}

.bold{
    font-weight: bold;
    font-size: 1.3em;
}

table tr:nth-child(odd) {
    background-color: yellow;
}
table tr:nth-child(even) {
    background-color: red;
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

you forget to use the <table> tag and your CSS address it from the table.

<?php
   echo "<table>";
    for($row=0; $row<=10; $row++){
        echo "<tr>";
        
        for($column=0; $column<=10; $column++){

            if($row==0 && $column==0){
                echo "<td></td>";
            }
                
            else{
                echo "<td>". $row * $column. "</td>";
            }
            
        }
        echo "</tr>";
    }
    
    echo "</table>";
    ?>
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