Christian,

> we have a directory with pics, that a user can associate with his data in a
> form. we use opendir/readdir to show the directory contents. unfortunately,
> this is not sorted. How can we achieve a listing in alphabetical order?
>
> this is our code:
>
> echo "<select name='image'>";
> echo "<option value=''>please select</option>";
> $fp = opendir("../pics/");
> while ($file = readdir($fp)) {
> $selectfile="/pics/".$file;
> if ($file=="." OR $file=="..") { } else {
> $string_image .= "<option value='/pics/".$file."'";
> if ($selectfile==$image) { $string_image .= " SELECTED"; }
> $string_image .= ">".$file."</option>";
> }
> }
> echo $string_image;
> echo "</select>";


=readdir -- read entry from directory handle
          string readdir (resource dir_handle)
Returns the filename of the next file from the directory. The
     filenames are not returned in any particular order.

=so it is not possible to retrieve the filenames in alpha sequence.

=Instead of taking the filenames directly from the readdir() and dropping them into 
the <option>, it may be
necessary to put them first into an array/list. At the end of the while loop, the 
array could be sorted, and
then another (for) loop implemented to copy the sorted list from the sorted array/list 
into the <option>s.

=Regards,
=dn



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to