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 7 of 7
  1. #1
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    Formatting A ( While )???

    I have some PHP:

    PHP Code:
    <?php
    $dir 
    "/";

    // Open a known directory, and proceed to read its contents
    if (is_dir($dir)) {
       if (
    $dh opendir($dir)) {
           while ((
    $file readdir($dh)) !== false) {
               echo 
    $file;
               echo 
    "<br />";
           }
           
    closedir($dh);
       }
    }
    ?>
    It checks all the files in a directory then list each file on a new line.
    Is there eny way of formatting each line for example the first line bg is grey the second is white the third is then grey and so on. How is this done???

  • #2
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    $dir 
    "/";

    // Open a known directory, and proceed to read its contents
    if (is_dir($dir)) {
       if (
    $dh opendir($dir)) {
           
    $i 0;
           while ((
    $file readdir($dh)) !== false) {
               if (
    $i == 0) { 
                          
    $color "#999999";
                          
    $i 1;
               }
               else {
                          
    $color "#CCCCCC";
                          
    $i 0;
               }
               echo 
    '<div style="background-color:' $color '">' $file '</div>';
               
    // echo "<br />";
           
    }
           
    closedir($dh);
       }
    }
    ?>

  • #3
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Thats Great!
    T H A N K S!

  • #4
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    i have my code:

    PHP Code:
    <?php
    $dir 
    "/";

    // Open a known directory, and proceed to read its contents
    if (is_dir($dir)) {
       if (
    $dh opendir($dir)) {
           
    $i 0;
           while ((
    $file readdir($dh)) !== false) {
               if (
    $i == 0) { 
                          
    $color "#999999";
                          
    $i 1;
               }
               else {
                          
    $color "#CCCCCC";
                          
    $i 0;
               }
               echo 
    '<div class="boxes"><div class="boxes" style="background-color:' $color '">' $file '</div></div>';
           }
           
    closedir($dh);
       }
    }
    ?>

    and then i want a check box for each one so you could delete the file.
    How???

    Ty!

  • #5
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    You'll have to have wrap your code with a form and dynamically write out a checkbox with each file:

    PHP Code:
    echo '<div class="boxes"><div class="boxes" style="background-color:' $color '"><input name="del_file" type="checkbox" value="' .$file .'" />' $file '</div></div>'
    This will make an array with the check box values...once you submit the form search to see which files have been checked and use the unlink() to delete them.
    Last edited by StupidRalph; 03-12-2007 at 09:33 PM. Reason: forgot to add value
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #6
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    I Don't Understand!

    Sorry ive been doing PHP for bout a year and a half but dident really learn anything!

  • #7
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    I've replied in your other thread here...

    http://www.codingforums.com/showthre...d=1#post544478
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

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