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

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

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