dragon_sa Posted November 28, 2009 Share Posted November 28, 2009 I am reading a directory and getting a list of folders in the directory, I want to display the folders in a table which is 6 columns of results across by how ever may rows, here is the code I am using now which gets the folders and displays the table correctly, but it is currently only displaying the first result in an infinite loop. <?php $d='action'; #define which dir you want to read $dir = opendir($d); #open directory while ($f = readdir($dir)) { /* echo '<a href="'.$f.'/index.htm" target="_parent"><img src="'.$d.'/'.$f.'/folder.jpg" border="0"></a><br>'; */ if ($f!="." && $f!=".." && (!is_file($f))) { echo '<table cellspacing="5" cellpadding="4" align="center">'; $tdcount = 1; while ($f) { if($tdcount % 6 == 1) echo "<tr>"; echo '<td><font face="arial" size="1">'; echo '<a href="'.$f.'/index.htm" target="_parent"><img src="'.$d.'/'.$f.'/folder.jpg" border="0"></a></td>'; if($tdcount % 6 == 0) echo "</tr>"; $tdcount++; } echo "</table>"; } } ?> How do i make it display each result instead of only the first result. cheers Link to comment https://forums.phpfreaks.com/topic/183208-displaying-unknown-amount-of-results/ Share on other sites More sharing options...
JAY6390 Posted November 28, 2009 Share Posted November 28, 2009 $chunks = 6; $dir = 'action'; $f = array_chunk(glob($dir.'/*', GLOB_ONLYDIR), $chunks); $last = count($f) - 1; while (count($f[$last]) < $chunks) { $f[$last][] = ''; } echo ' <table>'; foreach ($f as $row) { echo ' <tr>'; foreach($row as $folder) { if($folder === '') { echo ' <td> </td>'; }else{ echo ' <td style="font-face: Arial; font-size=1;"> <a href="'.$folder.'/index.html" target="_parent"> <img src="'.$folder.'/folder.jpg" style="border: none" /> </a> </td>'; } } echo ' </tr>'; } echo ' </table>'; Try that see a working example here http://temp.jaygilford.com/glob.php Link to comment https://forums.phpfreaks.com/topic/183208-displaying-unknown-amount-of-results/#findComment-966921 Share on other sites More sharing options...
dragon_sa Posted November 28, 2009 Author Share Posted November 28, 2009 perfect exactly what I was look for thank you Link to comment https://forums.phpfreaks.com/topic/183208-displaying-unknown-amount-of-results/#findComment-966927 Share on other sites More sharing options...
JAY6390 Posted November 28, 2009 Share Posted November 28, 2009 No problem Link to comment https://forums.phpfreaks.com/topic/183208-displaying-unknown-amount-of-results/#findComment-966931 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.