Recent Topics

1 Feb 17, 2006 23:23    

I am uncommonly tired right now, so if the answer to my question is obvious or I'm not making much sense, please forgive me.

I found some code on the internet that will scan a directory and return the names of the files in it (see below) as an array. What I would like to do is to take this array and make it part of a drop down list that can be selected when adding a post and also be attached to a database field.

I was looking at the code in form.class.php and there seem to be a few different functions that allow you to create a drop down list (select_object, select_input_options for example). My problem is that I cannot figure out how to incorporate my array of filenames into one of these functions and then attach it to the db field I want.

Any assistance would be much appreciated!
-awd


<?php
   $results = array();

    // create a handler for the directory
    $handler = opendir('$directory);

    // keep going until all files in directory have been read
    while ($file = readdir($handler)) {
        // if $file isn't this directory or its parent,
        // add it to the results array
        if ($file != '.' && $file != '..')
            $results[] = $file;
    }

    // tidy up: close the handler
    closedir($handler); ?>

2 Feb 18, 2006 06:07

Hi, bd80599. I'm the very definition of a novice when it comes to PHP, so my apologies it this isn't at all what you need, but it seems to me that you could create a fairly simple list like this by using mostly HTML. For example:

<select name="list">
<option value="value1"><?php echo $Class->results[0] ?></option>
<option value="value2"><?php echo $Class->results[1] ?></option>
<option value="value3"><?php echo $Class->results[2] ?></option>
<option value="value4"><?php echo $Class->results[3] ?></option>
<!-- etc... -->
</select>

About databases, though... I know nothing, I'm afraid. Hope this is at least marginally helpful.


Form is loading...