...

View Full Version : Read Dir help



SlayerACC
12-09-2010, 06:00 PM
With the code below. how could I make it so that if after it reads five out of the ten folders it goes to a new line or table??


//Open directory
$location=opendir("./");
echo "<table cellpadding=\"0\" cellspacing=\"0\" ><tr>";
//List items in directory
while(($directory=readdir($location)) !== false) {

//Directory filter
if($directory!= '.' && $directory!= '..'){
if(is_dir($directory)){

//Include index files from directories
echo "<td valign=\"top\" align=\"center\"><div id='".$directory."'>"; include($directory.'/index.php'); echo "</div></td>";}}}
echo "</tr></table>";
closedir($location);

Thanks, S.

DrDOS
12-09-2010, 11:11 PM
Declare an array, push all the entries into the array with array_push(), course over the array with a for loop and suitable conditional statements.

firepages
12-10-2010, 01:01 AM
too many ways : , simplistic would be as below & just echo a </tr><tr> every 5 iterations, if the total count is not divisible by 5 grab $tr value and make up the empty space at the end.



echo '<table><tr>';
$tr=$x=0;
while(++$x<=100){
/**the relevant bit*/
if($tr>=5){
echo '</tr><tr>';
$tr=0;
}
++$tr;
/**/
echo "<td>$x</td>";
}
echo '</tr></table>';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum