joshd963 Posted October 13, 2010 Share Posted October 13, 2010 Hi guys. Just a quick PHP question. I have a script running that gets the files from a directory. There is then a switch function that decides what to do with the file, ie... if it is a PNG... DO THIS.. if it is a docx... DO THIS.. etc. And i want each file to be in a different cell on the table. The table can be longer wider than 5 columns (however it can be as high as it wants). I currently have this bit working... but instead of one item in each cell... it is displaying every item in each cell. Any ideas Chaps? Here is my code Many thanks in advance if you could possibly help.. echo "<table><tr>"; $count = count(glob("../../shared/files/*.*", GLOB_BRACE)); for($i=1; $i <= $count; $i++) { /// echo "<td>"; /// if ($handle = opendir('../../shared/files/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $break = pathinfo($file); $b = $break['extension']; switch (@$break[extension]) { case 'bmp' : echo 'A BMP<br>'; break; case 'png' : echo 'A PNG<br>'; break; case 'doc' : case 'docx' : echo 'A DOC OR DOCX<br>'; break; default: echo 'FILE NOT RECOGNISED<br>'; } } } closedir($handle); } /// echo "</td>"; /// if($i % 3 == 0) echo "</tr><tr>"; } echo "</tr></table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/215773-get-filenames-from-directory-and-display-each-in-a-cell-no-wider-than-5-columns/ Share on other sites More sharing options...
Zane Posted October 13, 2010 Share Posted October 13, 2010 This, if($i % 3 == 0) echo ""; } Should be at the BEGINNING of your loop, not the end. Quote Link to comment https://forums.phpfreaks.com/topic/215773-get-filenames-from-directory-and-display-each-in-a-cell-no-wider-than-5-columns/#findComment-1121744 Share on other sites More sharing options...
joshd963 Posted October 13, 2010 Author Share Posted October 13, 2010 hmm.. im not entirely sure what you mean Regards Josh Quote Link to comment https://forums.phpfreaks.com/topic/215773-get-filenames-from-directory-and-display-each-in-a-cell-no-wider-than-5-columns/#findComment-1121756 Share on other sites More sharing options...
Zane Posted October 13, 2010 Share Posted October 13, 2010 This, if($i % 3 == 0) echo ""; } Should be at the BEGINNING of your loop, not the end. I mean this echo "</pre> <table>"; $count = count(glob("../../shared/files/*.*", GLOB_BRACE)); for($i=1; $i { /// Put it here if($i % 3 == 0) echo ""; } ///// echo ""; </ Quote Link to comment https://forums.phpfreaks.com/topic/215773-get-filenames-from-directory-and-display-each-in-a-cell-no-wider-than-5-columns/#findComment-1121760 Share on other sites More sharing options...
joshd963 Posted October 13, 2010 Author Share Posted October 13, 2010 "top nutter" Thanks a lot for your help :-) it now works, & i understand. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/215773-get-filenames-from-directory-and-display-each-in-a-cell-no-wider-than-5-columns/#findComment-1121761 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.