Jump to content

display 5 folders in directory... help


leijae

Recommended Posts

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 ); 
	} 
?>

Link to comment
https://forums.phpfreaks.com/topic/240741-display-5-folders-in-directory-help/
Share on other sites

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 ); 
				} 

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.