Jump to content

displaying unknown amount of results


dragon_sa

Recommended Posts

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

$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>&nbsp</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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.