Jump to content

Dynamic dropdown to split into optgroups..


Scooby08

Recommended Posts

How would I go about splitting these dynamically generated options into optgroups by using the directory names??  Here is an example of what is generated:

 

<select>
<option value="one/a.php">one/a.php</option>
    <option value="one/b.php">one/b.php</option>
    <option value="one/c.php">one/c.php</option>
    <option value="two/a.php">two/a.php</option>
    <option value="two/b.php">two/b.php</option>
    <option value="two/c.php">two/c.php</option>
    <option value="three/a.php">three/a.php</option>
    <option value="three/b.php">three/b.php</option>
    <option value="three/c.php">three/c.php</option>
</select>

 

This is what I'm trying to change that too:

 

<select>
<optgroup label="one">
<option value="one/a.php">one/a.php</option>
    <option value="one/b.php">one/b.php</option>
    <option value="one/c.php">one/c.php</option>
    </optgroup>
    <optgroup label="two">
    <option value="two/a.php">two/a.php</option>
    <option value="two/b.php">two/b.php</option>
    <option value="two/c.php">two/c.php</option>
    </optgroup>
    <optgroup label="three">
    <option value="three/a.php">three/a.php</option>
    <option value="three/b.php">three/b.php</option>
    <option value="three/c.php">three/c.php</option>
    </optgroup>
</select>

 

Could anybody get me pointed in the right direction??

I don't think I quite understand you... aren't one, two and three directories?

 

<?php

$base_dir = $_SERVER['DOCUMENT_ROOT']."/";

    // in your loop, get the folder names
    $folder = "images";

echo '<select>';

if (is_dir($base_dir.$folder))
{
    echo '<optgroup label="'.$folder'">';
    //next, go inside the folder and list all files
}
// move to the next level and start the process again.

echo '</select>';

?>

 

^^ this is what I meant. Of course, in your code things would be a little bit different but you get the idea.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.