Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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