Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!