Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Read Dir help

  1. #1
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    243
    Thanks
    51
    Thanked 3 Times in 3 Posts

    Read Dir help

    With the code below. how could I make it so that if after it reads five out of the ten folders it goes to a new line or table??

    PHP Code:
    //Open directory
    $location=opendir("./");
    echo 
    "<table cellpadding=\"0\" cellspacing=\"0\" ><tr>";
    //List items in directory
    while(($directory=readdir($location)) !== false) {

    //Directory filter
    if($directory!= '.' && $directory!= '..'){
    if(
    is_dir($directory)){

    //Include index files from directories
    echo "<td valign=\"top\" align=\"center\"><div id='".$directory."'>"; include($directory.'/index.php'); echo "</div></td>";}}}
    echo 
    "</tr></table>";
    closedir($location); 
    Thanks, S.

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,451
    Thanks
    17
    Thanked 275 Times in 275 Posts
    Declare an array, push all the entries into the array with array_push(), course over the array with a for loop and suitable conditional statements.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    too many ways : , simplistic would be as below & just echo a </tr><tr> every 5 iterations, if the total count is not divisible by 5 grab $tr value and make up the empty space at the end.

    PHP Code:
    echo '<table><tr>';
    $tr=$x=0;
    while(++
    $x<=100){
    /**the relevant bit*/
     
    if($tr>=5){
        echo 
    '</tr><tr>';
        
    $tr=0;
      } 
     ++
    $tr;
    /**/
     
    echo "<td>$x</td>";
    }
    echo 
    '</tr></table>'
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •