0

I'm currently looping SQL results from an Oracle table. All the rows from the table are returning fine, however they are all staying within on element instead of onto a new row like below

enter image description here

This is my current table...

   <div id="smtTable" class="targetDiv">
     <table width="40%" style="margin: 0 auto; border:1px solid;text-align:center; width: auto;" class="table table-sm table-dark">
         <tr>
           <th scope="col">Area</th>
           <th scope="col">Week 18</th>
           <th scope="col">Week 19</th>
           <th scope="col">Week 20</th>
           <th scope="col">Week 21</th>
           <th scope="col">Week 22</th>
         </tr>
<?php
 while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
     foreach ($row as $item) {
         echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
     }
 }
 ?>

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
mat1986
  • 135
  • 10

1 Answers1

1

You need to close table and add tr as it's tag for rows:

<?php
 while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {

echo '<tr>';
      foreach ($row as $item) {
     echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
      }
echo '</tr>';
 }
echo '</table>';
 ?>
Aksen P
  • 4,564
  • 3
  • 14
  • 27