Mod-Jay Posted May 4, 2011 Share Posted May 4, 2011 Okay i want line 18's DIV to actually not end on each repeat. im getting confused on how to do it. but everything i try it doesnt work. 1 <?php 2 function getDirectory( $path = '../toplist/', $level = 3 ){ 3 4 $ignore = array( 'cgi-bin', '.', '..', 'images', 'js', 'css', 'admin'); 5 $dh = @opendir( $path ); 6 7 while( false !== ( $file = readdir( $dh ) ) ){ 8 //$files = "<div class=\"msg_body\"><a href='edit.php?file=$file'>". $file ."</a> "; 9 if( !in_array( $file, $ignore ) ){ 10 11 $spaces = str_repeat( ' ', ( $level * 4 ) ); 12 if( is_dir( "$path/$file" ) ){ 13 echo "<p class=\"msg_head\"><strong>$spaces - $file</strong></p>"; 14 // echo "<strong>$spaces - $file<br /></strong>"; 15 getDirectory( "$path/$file", ($level+1) ); 16 } else { 17 18 echo "<div class=\"msg_body\">$spaces $file<br /></div>"; 19 // echo "$spaces $file<br />"; 20 } 21 22 } 23 24 } 25 closedir( $dh ); 26 27 } 29 ?> Quote Link to comment Share on other sites More sharing options...
fugix Posted May 4, 2011 Share Posted May 4, 2011 how would you like the information to be displayed? Quote Link to comment Share on other sites More sharing options...
Mod-Jay Posted May 4, 2011 Author Share Posted May 4, 2011 The header than i want the $file displayed in a the list_body div Quote Link to comment Share on other sites More sharing options...
fugix Posted May 4, 2011 Share Posted May 4, 2011 you could have you beginning and ending div tags outside of your function...then echo each instance of $spaces $files followed by a <br /> in your while loop as you have now Quote Link to comment Share on other sites More sharing options...
Mod-Jay Posted May 4, 2011 Author Share Posted May 4, 2011 Didnt work. Quote Link to comment Share on other sites More sharing options...
fugix Posted May 4, 2011 Share Posted May 4, 2011 should, whats the errors you receive? Quote Link to comment Share on other sites More sharing options...
Mod-Jay Posted May 4, 2011 Author Share Posted May 4, 2011 None. IT just did not work. Do you have an msn? Quote Link to comment Share on other sites More sharing options...
Drummin Posted May 4, 2011 Share Posted May 4, 2011 Is this what you're looking for? Or does it need to go outside the while statement? function getDirectory( $path = '../toplist/', $level = 3 ){ $ignore = array( 'cgi-bin', '.', '..', 'images', 'js', 'css', 'admin'); $dh = @opendir( $path ); while( false !== ( $file = readdir( $dh ) ) ){ if( !in_array( $file, $ignore ) ){ $spaces = str_repeat( ' ', ( $level * 4 ) ); echo "<div class=\"msg_body\">"; if( is_dir( "$path/$file" ) ){ echo "<p class=\"msg_head\"><strong>$spaces - $file</strong></p>"; echo "<strong>$spaces - $file<br /></strong>"; getDirectory( "$path/$file", ($level+1) ); } else { echo "$spaces $file<br />"; }//End ELSE echo "</div>"; }//END if( is_dir( "$path/$file" ) }//End while( closedir( $dh ); } Quote Link to comment Share on other sites More sharing options...
efficacious Posted May 4, 2011 Share Posted May 4, 2011 is this going to be building a bunch of div's inside of divs? if you don't end the div everytime thats what your ending up with. maybe i misread. Quote Link to comment Share on other sites More sharing options...
Drummin Posted May 4, 2011 Share Posted May 4, 2011 is this going to be building a bunch of div's inside of divs? if you don't end the div everytime thats what your ending up with. I agree. Those div's should be outside the while statement. I just moved it out of the IF ELSE statements as he requested. Quote Link to comment Share on other sites More sharing options...
Mod-Jay Posted May 5, 2011 Author Share Posted May 5, 2011 Atm the loop on line 18 , is making it only register as one file each msg_body div, and im trying to make it so it registers them All in the folder. Quote Link to comment Share on other sites More sharing options...
Mod-Jay Posted May 6, 2011 Author Share Posted May 6, 2011 Help? Quote Link to comment Share on other sites More sharing options...
spiderwell Posted May 6, 2011 Share Posted May 6, 2011 you could pass the loop at 18 to a concatenating string and wrap the div tags around it after the loop ends? then echo it out? Quote Link to comment Share on other sites More sharing options...
Mod-Jay Posted May 6, 2011 Author Share Posted May 6, 2011 Could you do the favor of perfecting the code. Quote Link to comment Share on other sites More sharing options...
spiderwell Posted May 6, 2011 Share Posted May 6, 2011 declare $somestring outside of the loops line 18: $somestring .= "$spaces $file<br />"; line 21: echo "<div class=\"msg_body\">$somestring</div>"; Quote Link to comment 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.