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
  1. #1
    Regular Coder
    Join Date
    Aug 2012
    Posts
    142
    Thanks
    39
    Thanked 3 Times in 3 Posts

    PHP form Select from list problem

    I've created a bunch of items that I want to include in a form. The list is successfully generated from a list of files using the following code:
    PHP Code:
    <?PHP
    // Create selection list from a directory
    # The current directory
    $directory dir("../includes/");

    # If you want to turn on Extension Filter, then uncomment this:
    $allowed_ext = array(".php"".png"".jpg"".jpeg"".txt"".doc"".xls"); 

    $i 0
    while(
    $file=$directory->read()) { 
        
    $file strtolower($file);
        
    $ext strrchr($file'.');
        if (isset(
    $allowed_ext) && (!in_array($ext,$allowed_ext)))
            {
                
    // dump 
            
    }
        else { 
            
    $temp_info stat($file); 
            
    $new_array[$i][0] = $file
            
    $i $i 1
            } 

    $directory->close(); 

    $i2 count($new_array); 
    $i 0
    echo 
    '<select name="include">
             <option value="n">None</option>'
    ;
             if (
    $row_pageContent['include'] <> 'n') {
                echo 
    '<option value="'.$row_pageContent['include'].
                
    '" selected="selected">' .$row_pageContent['include'].
                
    '</option>'
                
    ;}  
             ; 
    for (
    $i=0;$i<$i2;$i++) { 
        if (!
    $do_link){ 
            
    $line '<option value = '$new_array[$i][0] . '>' .  
                            
    $new_array[$i][0] .  
                            
    '</option>'
        }
            
        echo 
    $line

    echo 
    '</select>'

    ?>
    This works fine but I end up with a duplicate file name in the list if one is selected. Any ideas on how to eliminate the duplicate by putting the if statement that looks for a file name other than n in the code that generates the option list ($list);

    Any help or ideas would be appreciated.
    Last edited by rgEffects; 08-19-2013 at 05:41 PM.

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,903
    Thanks
    15
    Thanked 226 Times in 226 Posts
    I would try just making an array, on the fly, of the files that have already been included, and using an if(!in_array statement to avoid duplication.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #3
    Regular Coder
    Join Date
    Aug 2012
    Posts
    142
    Thanks
    39
    Thanked 3 Times in 3 Posts
    Any suggestions about how to do that?


  •  

    Posting Permissions

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