White_Lily Posted December 1, 2012 Share Posted December 1, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/271439-listing-directory-files/ Share on other sites More sharing options...
DavidAM Posted December 1, 2012 Share Posted December 1, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271439-listing-directory-files/#findComment-1396664 Share on other sites More sharing options...
White_Lily Posted December 1, 2012 Author Share Posted December 1, 2012 Since clearly help can't be given, I have done things a bit differently and managed to get the same result. Therefore this topic is solved. Quote Link to comment https://forums.phpfreaks.com/topic/271439-listing-directory-files/#findComment-1396675 Share on other sites More sharing options...
Pikachu2000 Posted December 1, 2012 Share Posted December 1, 2012 Clearly, help was given. If you chose to ignore it and do something else, then that's your prerogative. Quote Link to comment https://forums.phpfreaks.com/topic/271439-listing-directory-files/#findComment-1396677 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.