foreach dropdown menu

Discussion in 'PHP' started by zodiac, Sep 15, 2009.

  1. #1
    <?php
    
    
    $dir = '/home/....';
    $files = scandir($dir);
    foreach ($files as &$file) {
    if ($file!='.' && $file!='..' )
    {
    ?>
    <select name="main">
    
    <option value =""><?=$file?></option>
    </select>
    <?
    }
    }
    ?> 
    Code (markup):
    that selects the folders in the directory,but that makes a dropdown menu for each folders name.
    i'm looking for all the folder names to be in one dropdown menu. ;)
     
    zodiac, Sep 15, 2009 IP
  2. ASTURIAS

    ASTURIAS Member

    Messages:
    239
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #2
    Try this:

    <?php
    $dir = '/home/....';
    $files = scandir($dir);
    print '<select name="main">';
    foreach ($files as &$file) {
    if ($file!='.' && $file!='..' )
    {
    ?>
    <option value =""><?=$file?></option>
    <?
    }
    }
    print '</select>';
    ?>
    Code (markup):
     
    ASTURIAS, Sep 15, 2009 IP
    zodiac likes this.