Scooby08 Posted January 7, 2009 Share Posted January 7, 2009 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?? Link to comment https://forums.phpfreaks.com/topic/139775-dynamic-dropdown-to-split-into-optgroups/ Share on other sites More sharing options...
julia k Posted January 7, 2009 Share Posted January 7, 2009 You didn't posted the way you get that files, but try to check using the is_dir function to see if it's a directory. if true, then create the optgroup using its name, and add the files into the option tags. Link to comment https://forums.phpfreaks.com/topic/139775-dynamic-dropdown-to-split-into-optgroups/#findComment-731260 Share on other sites More sharing options...
Scooby08 Posted January 7, 2009 Author Share Posted January 7, 2009 They are all files in directories.. None will just be a plain directory.. Link to comment https://forums.phpfreaks.com/topic/139775-dynamic-dropdown-to-split-into-optgroups/#findComment-731273 Share on other sites More sharing options...
julia k Posted January 7, 2009 Share Posted January 7, 2009 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. Link to comment https://forums.phpfreaks.com/topic/139775-dynamic-dropdown-to-split-into-optgroups/#findComment-731644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.