I have this table:
img id | img_path | listing_assoc_id| ---------------------------------------- 11 |img/img1.jpg | 12 | 12 |img/img2.jpg | 12 | 13 |img/img3.jpg | 12 | 14 |img/img4.jpg | 12 | 15 |img/img5.jpg | 12 | 16 |img/img6.jpg | 12 | 18 |img/img7.jpg | 12 | 21 |img/img8.jpg | 12 | 22 |img/img9.jpg | 12 | 23 |img/img10.jpg| 12 | 24 |img/img11.jpg| 12 |
And I want to display it into a table in html
like this maximum of 5 images per row. I have been fiddling with different loops in combination of different loops like above for a couple hours but haven't found one that works like I need. They are either displaying the same images across the entire row or are messed up in some other way. Obviously need to use tr & td elements to format table correctly.
What I need:
<tr> <td>img1</td> <td>img2</td> <td>img3</td> <td>img4</td> <td>img5</td> </tr> <tr> <td>img6</td> <td>img7</td> <td>img8</td> <td>img9</td> <td>img10</td> </tr> <tr> <td>img11</td> </tr>Some of the code that doesn't work:
$query = "SELECT * FROM listings_gallery WHERE listing_assoc_id = " 12 " ORDER BY img_id ASC"; $image_set = mysqli_query($connection, $query); echo '<tr>'; while($img = mysqli_fetch_assoc($image_set)){ while($img['img_id'] < 5){ echo "<td><img src='" . $img['img_path'] . "'></td>"; } echo '<tr>'; }