leijae Posted June 29, 2011 Share Posted June 29, 2011 Say there's 10 folders in this directory... right now its: folder1 1 folder1 2 folder1 3 folder1 4 folder1 5 folder2 6 folder3 7 folder4 8 folder5 9 folder6 10 what i want is: folder1 1 folder2 2 folder3 3 folder4 4 folder5 5 STOP HERE Please help. <?php getDirectory('webs/sum2011'); function getDirectory( $path = '.', $level = 0 ) { $ignore = array( '.', '..' ); $dh = @opendir( $path ); $i = 0; while( false !== ( $file = readdir( $dh ) ) ) { if( !in_array( $file, $ignore ) ) { do { $i++; if(is_dir( "$path/$file" ) ) { echo "<a href='$path/$file/index.php'>$file $i</a><br />"; getDirectory( "$path/$file", ($level+1) ); } } while ($i < 5); } } closedir( $dh ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/240741-display-5-folders-in-directory-help/ Share on other sites More sharing options...
requinix Posted June 29, 2011 Share Posted June 29, 2011 You already have a loop that you can use - you don't need another. $i = 0; while (has files && $i $i++; rest of the code } Quote Link to comment https://forums.phpfreaks.com/topic/240741-display-5-folders-in-directory-help/#findComment-1236563 Share on other sites More sharing options...
leijae Posted June 29, 2011 Author Share Posted June 29, 2011 that sorta works, but now it only displays correctly if i set $i = -2; function getDirectory( $path = '.', $level = 0 ) { $ignore = array( '.', '..' ); $dh = @opendir( $path ); $i = -2; while( false !== ( $file = readdir( $dh ) ) && ( $i < 5) ) { $i++; if( !in_array( $file, $ignore ) ) { if(is_dir( "$path/$file" ) ) { echo "<a href='$path/$file/index.php'>$file $i</a><br />"; getDirectory( "$path/$file", ($level+1) ); } } } closedir( $dh ); } Quote Link to comment https://forums.phpfreaks.com/topic/240741-display-5-folders-in-directory-help/#findComment-1236573 Share on other sites More sharing options...
requinix Posted June 29, 2011 Share Posted June 29, 2011 Right. Because of the two ignored directories. Use $i=0 and move the $i++ somewhere else... Quote Link to comment https://forums.phpfreaks.com/topic/240741-display-5-folders-in-directory-help/#findComment-1236580 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.