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

133
Visualizações
Populate a row on a td on php javascript

i have this code:

            <table id="table" style="width: 100%; text-align: center;" border="0">
            <?php while ($row = $q->fetch()): ?>
                <tr>
                    <th></th>
                    <th></th>
                </tr>

                <tr>
                    <td id="columna1">
                <div class="col-lg-12" >
                        
                            <div class="food-grid-item grid-style-one">
                            <br>
                            <br>
                                    <div class="food-thumb grid-item">
                                    <img src="assets/images/foodmenu/<?php echo $row['imagen']?>" href="#foodmenu1">
                                    </div>
                                    <div class="food-info grid-item">
                                        <h3 class="food-title grid-item"><?php echo $row['product_name']?></h3>
                                        <p><?php echo $row['descripcion']?></p>
                                        <div class="food-price grid-item"><span>$</span><?php echo $row['price']?></div>
                                        <div class="food-cart-tools grid-item">
                                            <a href="#" class="food-cart btn btn-default">Add to cart</a>
                                        </div>
                         
                                    </div>
                                </div>                        
                        </div>  
             
                     </td>

                    <td id="columna2">
                  
                    </td>
                 
                </tr>
                <?php endwhile; ?>
            </table>

as you can see, the "columna2" td, is empty cause i want to populate each database row on each to get the population in 2 columns and i don't know how to make it. it's something like this:

1 2

3 4

5 6

I try to do it on diferent ways but have no luck! Please if yo need more details please let me know i am new.

Thank you all

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Start by putting all of the results in an array first.

$num = mysqli_num_rows($query);
$result_array = [];
for($i = 1; $i <= $num; $i++) {
    $result         = mysqli_fetch_array($query);
    $result_array[] = $result;
}

And start to construct a table using a loop.

<table>
    <thead>
    <tr>
        <th>| Column 1 |</th>
        <th>| Column 2 |</th>
    </tr>
    </thead>
    <tbody>
    <?php
    $column_size = 2;

    for($row = 0; $row < $num / $column_size; $row++) {
        echo '<tr>';
        for($column = 0; $column < $column_size; $column++) {
            echo '<td>';
            echo 'ID: '.$result_array[($row * $column_size) + $column]['u_id'];
            echo '</td>';
        }
        echo '</tr>';
    }
    ?>
    </tbody>
</table>

The result: https://i.stack.imgur.com/CQSny.png

about 4 years ago · Juan Pablo Isaza 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