Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda