Results 1 to 2 of 2

Thread: While Loop - New Row Every 5

  1. #1
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default While Loop - New Row Every 5

    I'm running through images in a directory and outputting them into a table for display. I've attempted, rather wrongly, to echo '</tr><tr>' every 5 images, but the '</tr><tr>' shows up at the END of the echoed images. I know I'm probably going to need a for loop instead, or some combination of for and while. Anyway, here's my current code; any help is appreciated.

    PHP Code:
    $dir_handle = @opendir($path) or die("Unable to open folder"); 
    $num_imgs 0;
    $five_array = array(5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100);
    while (
    false !== ($file readdir($dir_handle))) {
        if(
    $file == ".")
            continue;
        if(
    $file == "..")
            continue; 
        
    $each1 '                <td><img src="../imgs/blog/'.$file.'" alt="http://number12foundation.org/imgs/blog/'.$file.'" /><br /><i>'.$file.'</i><br /><a href="admin.php?page=blogs&blog_page=images&images_page=delete&file='.$file.'">[delete]</a></td>'."\n";
        if(!
    in_array($num_imgs,$five_array)){
            echo 
    $each1;
        }
        else{
            echo 
    $each1;
            echo 
    "\n".'            </tr><tr>'."\n";
        }
        
    $num_imgs++;

    Thanks!
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  2. #2
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Figured it out:

    PHP Code:
    $dir_handle = @opendir($path) or die("Unable to open folder"); 
    $num_imgs 0;
    while (
    false !== ($file readdir($dir_handle))) {
        if(
    $file == ".")
            continue;
        if(
    $file == "..")
            continue; 
        
    $num_imgs++;
        if(
    $num_imgs%5==0){ echo "\n".'            </tr><tr>'."\n";}
        echo 
    '                <td><img src="../imgs/blog/'.$file.'" alt="http://number12foundation.org/imgs/blog/'.$file.'" /><br /><i>'.$file.'</i><br /><a href="admin.php?page=pages&pages_page=delete_img&img_path=blog__'.$file.'">[delete]</a></td>'."\n";

    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

Bookmarks

Posting Permissions

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