title: How to output table serial numbers in vertical format using PHP and MySQL
body: <p>I have the following piece of code to output the student data in HTML table with serial number in vertical format, but I can't understand the logic where I would use the while loop. The desired output show in images
  <a href="https://i.stack.imgur.com/qg3Bc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qg3Bc.png" alt="enter image description here" /></a></p>
  <pre><code>&lt;?php
  $query = mysqli_query($conn,&quot;SELECT * FROM `students` WHERE student_status = 'active' &quot;);
  
  $col = 4;  //number of desired columns 
  $row = 5;  //number of desired rows
  $output = '';
  $output .='&lt;table&gt;';
  while($row = mysqli_fetch_array($query)){
      for($i = 1; $i&lt;$row+1; $i++){
          $output .='&lt;tr&gt;';
          for($c = 0; $c&lt;$col; $c++){
              $output .='&lt;td&gt;'.($i + ($c*$row)).'&lt;/td&gt;';
              $output .='&lt;td&gt;Here i need the student name fetch from DB&lt;/td&gt;';
          }
          $output .='&lt;/tr&gt;';
      }
  }
  
  $output .='&lt;/table&gt;';
  echo $output;
  ?&gt;
  </code></pre>