title: How to create a table in HTML using PHP
body: <p>I have 5 pictures stored in a folder and their links stored on the database.
  I want to put them in a table of three columns on each row.</p>
  
  <pre><code>&lt;body&gt;
  &lt;center&gt;
  &lt;table border='1'&gt;
  &lt;?php
  $host="";
  $username="";
  $password="";
  $db_name="fruits_db";
  $tbl_name="fruits_tbl";
  $connection=mysqli_connect("$host","$username","$password","$db_name");
  if (mysqli_connect_errno())
  {
      echo "The application has failed to connect to the mysql database server: " .mysqli_connect_error();
  }
  $result = mysqli_query($connection, "SELECT * FROM fruits_tbl")or die("Error: " . mysqli_error($connection));
  $num_rows=mysqli_num_rows($result);
  $rows =  $num_rows/3;
  
  for($i=1; $i&lt;=$rows ; $i++)
  {
      echo "&lt;tr&gt;";
      for($j=1; $j&lt;=3; $j++)
      {
          while($row = mysqli_fetch_array($result))
          {
              echo
              ("&lt;td width='180px' height='200px'&gt;"
               ."&lt;div class = 'fruit_image'&gt;"
               ."&lt;img src='"
               .$row['fruit_image']
               ."'/&gt;"
               ."&lt;/div&gt;"
               ."&lt;div class = 'fruit_title'&gt;"
               .$row['fruit_name']
               ."&lt;/div&gt;"
               ."&lt;/td&gt;"
              );
          }
      }
      echo "&lt;/tr&gt;";
  }
  
  mysqli_close($connection);
  ?&gt;
  &lt;/table&gt;
  &lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The above code I created, contains two FOR loops. The script should count the number of rows in the table, and then divide by 3(the number of columns on each row in the HTML table).
  I wonder where I'm going wrong wit this code.</p>