title: Table inside nested Table
body: <p>I am having a nested table with a while loop, I want to add one more nested table in the same row: </p>
  
  <p><a href="https://i.stack.imgur.com/xSVoO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xSVoO.png" alt="nested table"></a></p>
  
  <p>Now I want to add one more nested table as each cd contains more than one data like below:</p>
  
  <p><a href="https://i.stack.imgur.com/v1qbN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v1qbN.png" alt="Double nested table"></a></p>
  
  <p>My code is as follows</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['viewcd'])){
  $queryw = "select * from lib_cd where id=".$_POST['idd'];
  $resultw = $mysqli-&gt;query($queryw);
  ?&gt;
  &lt;div&gt;
  &lt;table border="1"&gt;
    &lt;thead&gt;
      &lt;tr &gt;&lt;th &gt;Select&lt;/th&gt;
           &lt;th&gt;Well_Number&lt;/th&gt;
           &lt;th&gt;Well_Name&lt;/th&gt;
           &lt;th&gt;CD No:&lt;/th&gt;
           &lt;th &gt;Logs&lt;/th&gt;
       &lt;/tr&gt;
     &lt;/thead&gt;
    &lt;?php
    while($rowcd = $resultw-&gt;fetch_assoc()){
    ?&gt;
          &lt;tr&gt;
          &lt;td&gt;&lt;?php echo $rowcd['id'] ?&gt; &lt;/td&gt;
          &lt;td&gt;&lt;?php echo $rowcd['well_no'] ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $rowcd['well_name'] ?&gt;&lt;/td&gt;
          &lt;td&gt;
              &lt;table border="1" width="100%"&gt;
     &lt;?php
     $querycd = "select * from cd where pidd=".$rowcd['id'];
     $resultcd = $mysqli-&gt;query($querycd);
     while($rowcd = $resultcd-&gt;fetch_assoc()){
     ?&gt;
                  &lt;tr&gt;
                      &lt;td &gt;&lt;?php echo $rowcd['cd_no'] ?&gt;&lt;/td&gt;
     /* I want to add one more nested table here*/
                  &lt;/tr&gt;
    &lt;?php
     }
    ?&gt;
              &lt;/table&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
   &lt;?php
    }
    }
    ?&gt;
   &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I tried some thing like this,after my second while loop</p>
  
  <pre><code>    while($rowcd = $resultcd-&gt;fetch_assoc()){
       ?&gt;
                  &lt;tr&gt;
                      &lt;td &gt;&lt;?php echo $rowcd['cd_no'] ?&gt;&lt;/td&gt;
                  &lt;td&gt;
                    &lt;table&gt;
        &lt;?php
     $queryl = "select * from lib_cd_logs where pid=".$rowcd['cd_no'];
     $resultl = $mysqli-&gt;query($queryl);
     while($rowl = $resultl-&gt;fetch_assoc()){
     ?&gt;
                      &lt;tr&gt;
                        &lt;td&gt;&lt;?php echo $rowl['logs'] ?&gt;&lt;/td&gt;
                      &lt;/tr&gt;
     &lt;?php
     }
    ?&gt;
                  &lt;/tr&gt;
    &lt;?php
     }
    ?&gt;
              &lt;/table&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
   &lt;?php
    }
    }
    ?&gt;
   &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>but the result was messed up. I am confused, where I want to end my while loop, I think.</p>
  
  <p><a href="https://i.stack.imgur.com/gPgSc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gPgSc.png" alt="enter image description here"></a></p>