php - Output SQL table with
I am very new to PHP, but have done some reading on it. I have tried this varies ways and can't find a solution, but feel that there should definitely be one.
I am trying to display a SQL table with PHP - this is easy, I know. Next I am displaying all my data (images) in columns to run vertically (to make it display nicely). - for it to run display in columns, this is what my mind came up with:
- get the amount of data in SQL database (25 rows for example) $dataoutput
- divide it by 4 (4 columns) $dataoutput / 4 = 5
- display the table with a FOR function (run only if SQL result is smaller than the result (5)
- add a at the end of the 5 outputted images.
- Get the process to start all over again for 4 times (4 columns).
I've changed the code back to the basics - so it will works again.
<?php
$sql = "SELECT * FROM allthaimgs ORDER BY id ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<div >
<div >
<img src="../imgs/galary/zoom.png" >
<div ></div>
<img src="../imgs/galary/imgs/<?php echo $row["imgs"];?>" onclick="openModal();currentSlide(<?php echo $row["id"];?>)" >
</div>
</div>
<?php
}
} else {
echo "0 results";
}
$conn->close();
?>