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.


    $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"];?>)" >


    } else {
      echo "0 results";


People are also looking for solutions to the problem: php - How can I schedule a function to run, after one of my function is completed, after a specific time period in laravel?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.