alright...can't seem to get the right way to display my menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danselstudios
Forum Newbie
Posts: 24
Joined: Sat Jun 03, 2006 10:47 am
Location: Corona, CA

alright...can't seem to get the right way to display my menu

Post by danselstudios »

ok, i'm trying to dynamically create a menu page that reads all my contents in a directory.
example directory:
dev/php/basicpages/ --> has these files [ index.php, tut.php, nav.php ]
dev/php/intermediate/ --> has these files [ index.php, tut.php, functions.php, classes.php ]
dev/flash/ --> has these files [ mainflash.html, index.html, movie.swf, check.swf ]
dev/flash/movie assets/ --> has these files [ nav.as, functions.as, section.swf ]

example display:
php
php/basicpages
index.php
tut.php
nav.php
php/intermediate
index.php
tut.php
functions.php
classes.php
flash
mainflash.html
index.html
movie.swf
check.swf
flash/movie assets
nav.as
functions.as
section.swf

I need help with the display of this menu so looks like this:
php
basics
index.php
tut.php
nav.php
intermediate
index.php
tut.php
functions.php
classes.php
flash
mainflash.html
index.html
movie.swf
check.swf
movie assets
nav.as
functions.as
section.swf

here is my script:
<table border="0" cellpadding="0" cellspacing="0">

Code: Select all

<?php
read_dir("."); 
function read_dir($dir) {  
   $path = opendir($dir);  
   while (false !== ($file = readdir($path))) {  
       if($file!="." && $file!=".." && $file!="menu.php" && $file!="styles.css" ) {
           if(is_file($dir."/".$file))
               $files[]=$file;
           else
               $dirs[]=$dir."/".$file;           
       }
   }
   if($dirs) {
       natcasesort($dirs);
       foreach($dirs as $dir) {
	     $dir = trim($dir,"./");
           echo '<tr><td class="subtitle">'.$dir.'</td></tr>';
           read_dir($dir);
       }
   }
   if($files) {
       natcasesort($files);
       foreach ($files as $file)
           echo '<tr><td><a href="'.$dir.'/'.$file.'">'.$file.'</a></td></tr>';
   }
   closedir($path);
}
?>
</table>

any help would be greatly appreciated and any links to tutorials would be great too. thanks
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Post Reply