php Multiple looping problem
<p>Im writing a function to get the parent and child ids but for the third loop there is a </p>

<p>problem the loop gets even the previous loops id also .</p>

<p>How can i avoid it?</p>

<pre><code>&lt;?
$results = '
&lt;table&gt;
    &lt;thead&gt;
        &lt;tr &gt;
            &lt;td id="ticket" align="center" &gt;&lt;b&gt;Task&lt;br /&gt;ID&lt;/b&gt;&lt;/td&gt;
            &lt;td id="ticket" align="center" &gt;&lt;b&gt;col1&lt;/td&gt;
            &lt;td id="ticket" align="center" &gt;&lt;b&gt;col2&lt;/td&gt;
&lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;';

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) 
{
$results .='
        &lt;tr &gt;
            &lt;td align="center"&gt;
                &lt;a href="UpdateTask.php?TaskID='.$row['Task_id'].$filterstring.'"&gt;'.$row['Task_id'].'&lt;/a&gt;
            &lt;/td&gt;';

    $results .= '&lt;td align="center"&gt;'; 
      $gg = mysqli_query($dbc,"select * from Tasks where ParentTask_Id='".$row['Task_id']."'");
      echo "&lt;br&gt;";     
            while ($rowdd = mysqli_fetch_assoc($gg)) 
      {
       $results .= $rowdd['Task_id']."&lt;br&gt;&lt;br&gt;"; 
       $gg2 = mysqli_query($dbc,"select * from Tasks where ParentTask_Id='".$rowdd['Task_id']."'");
       while ($rowdd2 = mysqli_fetch_assoc($gg2)) 
      {
         $results2 = $rowdd2['Task_id']."&lt;br&gt;&lt;br&gt;";
      } 
      echo "&lt;br&gt;";    
      } 
    // $results .= $car ;
        // $results .=  $t; 
            $results .='&lt;/td&gt;';
             $results .=' &lt;td  align="left" &gt;'?&gt;
        &lt;?
        $results .= $results2;  
        $results .='&lt;/td&gt;';
$results .='
        &lt;/tr&gt;';
}
?&gt;
</code></pre>
