title: creating table rowspan php
body: <p>i need help with my code..how do i have output like in the image below where it will automatically insert rowspan ..my current code</p>
  <pre><code>$result = $cmsDB-&gt;query(&quot;SELECT * FROM &quot;.$cmsDB-&gt;prefix(&quot;departments&quot;).&quot;&quot;);
  
  echo &quot;&lt;br /&gt;&lt;br /&gt;&lt;table class='table table-bordered table-striped'&gt;
  &lt;tr&gt;
  &lt;th&gt;Bil&lt;/th&gt;
  &lt;th&gt;Department&lt;/th&gt;
  &lt;th&gt;Staff&lt;/th&gt;
  &lt;/tr&gt;&quot;;
  
  $count =1 ;
  
  while($row = $cmsDB-&gt;fetchArray($result))
  {
  $deptid=$row['deptid']; 
  $deptname=$row['deptname']; 
   
  echo &quot;&lt;tr&gt;&lt;td&gt;&quot;.$count++.&quot;&lt;/td&gt;&lt;td&gt;&quot;.$deptname.&quot;&lt;/td&gt;&lt;td&gt;&quot;;
  global $cmsDB;
    $result2 = $cmsDB-&gt;query(&quot;SELECT * FROM &quot;.$cmsDB-&gt;prefix(&quot;staff&quot;).&quot; WHERE deptid=$deptid&quot;);
    
  while($row = $cmsDB-&gt;fetchArray($result2))
  {
  
  $name=$row['name']; 
  echo &quot;&quot;.$name.&quot; &lt;br /&gt;&quot;;
  
  }
  
  }
  
  
  echo &quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/65v7x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/65v7x.png" alt="current output" /></a></p>
  <p><a href="https://i.stack.imgur.com/4pALZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4pALZ.png" alt="Desired result" /></a></p>
  <p>current output and desired results</p>