I have trouble formatting my table data. The picture explains my problem. I have tried to use the foreach and then add a new in the foreach. but then i takes all for all of my documents i have in my entire database, when i only want the the ones for that id.

[![enter image description here](https://i.stack.imgur.com/n9Uwp.png)](https://i.stack.imgur.com/n9Uwp.png)

This is my code of the table:

```
<table class="table table-hover" style="font-size:100%!important" id="prover">
        <tr style="cursor:default!important;">
            <th>ID</th>
            <th>Navn</th>
            <th>CPR</th>
            <th>Dokumenter</th>                
            <th></th>
        </tr>
    <?php while ($row = mssql_fetch_array($results)):
            $docs = dbHelper::getTestDoc( $row[id] );?>

        <tr style="cursor:default!important;">
            <td><?php echo utf8_encode($row['id']); ?></td>
            <td><?php echo utf8_encode($row['navn']); ?></td>
            <td><?php echo $row['cprnr'] ?></td>

            <?php  while ($docrow = mssql_fetch_array($docs)){ ?>

            <td><?php  echo '<span>';

                             for ($i = 0; $i < count($docrow['docID']); ++$i) 
                             {
                                 if($i == 1 || 2)                                         
                    if ($docrow['Approved'] == 1){
                        echo '<span class="btn btn-success btn-xs pull-left" id="'.$docrow['docID'].'" title="" data-toggle="tooltip" data-original-title="Godkend dokument"><i class="fa fa-check-square"></i></span>
                        &nbsp;&nbsp;&nbsp;';
                    }else{
                        echo '<span class="btn btn-warning btn-xs pull-left aprove-doc" id="'.$docrow['docID'].'" title="" data-toggle="tooltip" data-original-title="Godkend dokument"><i class="fa fa-square"></i></span>
                                &nbsp;&nbsp;&nbsp;';
                                                    echo '<span class="btn btn-info btn-xs pull-left denied-doc" id="'.$docrow['docID'].'" title="" data-toggle="tooltip" data-original-title="Afvis dokument"><i class="fa fa-square"></i></span>
                                &nbsp;&nbsp;&nbsp;';

                    }
                echo    '<a href="../blabla.php?did='.$docrow['docID'].'">'.utf8_encode($docrow['displayName']). '</a> ';

                                            if ($docrow['DocType'] == 1){
                                                echo '(Afs. praktik)';
                                            }else if ($docrow['DocType']==2){
                                                echo '(Vdr. skema)';                        
                                            }else 
                                                echo '';                                            

                        echo '<span class="btn btn-danger btn-xs pull-right delete-doc" id="'.$docrow['docID'].'" title="" data-toggle="tooltip" data-original-title="Slet"><i class="fa fa-times"></i></span>
                    </span><br/>';

                            }    

            }  ?>

            </td>

            <td><input type="hidden" name="id" value="<?php echo $row[id] ?>"  <?php //echo $row['selected'] ?> ></td>
        </tr>

    <?php endwhile;?>
    </table>

```