Jump to content

Recommended Posts

Hi, I have a problem where my while loop isn't displaying what I have asked it to display, everything works except for this while loop and I can't see what the problem is code below:

 

while (false !== ($entry = readdir($handle)) && $fileGet = mysql_fetch_assoc($getfile)) {

if ($entry != "." && $entry != "..") {

$listFile = '<td>'.$entry.'</td>';

echo '<tr>';
echo '<td>'.$fileGet["file_name"].'</td>';
echo $listFile;
echo '<td>'.$fileGet["file_url"].'</td>';
echo '<td><a href="delete-file.php?id='.$fileGet["file_id"].'&file='.$fileGet["file_original"].'">Delete</a>
</td>';
echo '</tr>';


}
}

 

Any Ideas? Thanks - Lily

Link to comment
https://forums.phpfreaks.com/topic/271439-listing-directory-files/
Share on other sites

If it is not displaying what you asked it to display, what is it displaying. There's not a lot of room inside the loop for failure. What I do see is that you are retrieving an entry from the filesystem and an entry from the database at the start of each loop iteration. Then you are assuming that the two entries are for the same file or directory. However, since you do not process the current and parent directories ("." & "..") you are discarding two entries from the database (unless those two entries are in the database as well).

 

Personally, I would not depend on the two lists (readdir and the query) to return the same data in the same sequence. I would retrieve one set in an array and then loop through the other set matching to the array.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.