PHP + MySQL while()in while()只删除数据库中的第一个结果

First off, I know this is wrong. I just don't know a workaround or how to implent it.

This is my code:

$description_query = "SELECT * FROM documents WHERE owner = '".$_SESSION['username']."' AND id = '".$deletefileid."'";
$description = mysql_query( $description_query, $connection ) or die(mysql_error());

$description_files_query = "SELECT filename FROM documents_files WHERE besitzer = '".$_SESSION['username']."' AND vertrag_id = '".$deletefileid."'";
$description_files = mysql_query( $description_files_query, $connection ) or die(mysql_error());

while($row = mysql_fetch_array($description_files))
{   
    while($row1 = mysql_fetch_array($description))
    {

        if (!is_dir('./docs/archiv/'.$row1['vertragsnummer'])) {
            mkdir('./docs/archiv/'.$row1['vertragsnummer']);         
        }

        $filename = './docs/'.str_replace("./docs/", "", $value);
        $newfilename = './docs/archiv/'.$row1['vertragsnummer'].'/'.str_replace("./docs/", "", $value);
        rename($filename, $newfilename);

    }

}

Now the code first selects info about the entry, then moves the files, but if its more than one file, it moves only the first one in the result.

This is because of the first while as it always selects only one entry and then it stops working from the top.

How would I solve that? really confused.

Thanks

You can eliminate to duplicate whiles by doing the join in the database:

$description_query = "SELECT * FROM documents d inner join documents_files df on (d.id = df.vertrag_id)  WHERE d.owner = '".$_SESSION['username']."' AND d.id = '".$deletefileid."'";