I have a form which has a list of 20 select boxes to choose button images, each select box displaying the same file list from the images folder and on the right of the select box is a preview of the selected image.
The page also has code that checks if the submit button has been pressed and if so, updates the filename for each button in the DB.
The code for each of the 20 select boxes is very similar, here is an example:
<?php
$current_dir = '../images/';
$dir = opendir($current_dir);
echo ' <select type=text name=headCartLogo size=1 maxlength=50>';
while ($file = readdir($dir)) {
if ($file !== "." && $file !== ".." ) {
if ($file == $headCartLogo){
echo "<option selected>$file</option>";
} else {
echo "<option>$file</option>";
}
}
}
echo '</select>';
closedir($dir);; ?>
I want to standardize this code and put in a function which I will call each time. For example, I would call:
<?php
display_button_fuction('headCartLogo',$headCartLogo);
?>
<?php
function display_button($name,$button)
{
$current_dir = '../images/';
$dir = opendir($current_dir);
echo ' <select type=text name=$name size=1 maxlength=50>';
while ($file = readdir($dir))
{
if ($file !== "." && $file !== ".." )
{
if ($file == $button)
{
echo "<option selected>$file</option>";
}
else
{
echo "<option>$file</option>";
}
}
}
echo '</select>';
closedir($dir);
}
?>
I have tried this and the filelist is displayed ok, but how do I get the result from the function (which would be the item selected) back into the main page? The display function is on a functions page.
If any of the question does not make sense then let me know and I'll try to clarify it.