Jump to content

[SOLVED] Simple question about a drop down list


Stagnate

Recommended Posts

Hey guys, im just starting out with PHP and im making a website that hosts some images. Its going great so far but I want to have a drop down that can show my albums.

 

such as:

 

          <form name="form" id="form">

            <select name="jumpMenu" class="dropdown" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">

              <option value="#" selected="selected">Browse</option>

              <option value="#">Ground - Concrete</option>

              <option value="#">Grass</option>

              <option value="#">Metal</option>

              <option value="#">Graffiti</option>

            </select>

          </form>

 

I want the entrys for this to come from my images folder. For example if i have images/holiday then holiday will come up in the list.

 

Is there anywhere I can get an example of this?

Link to comment
Share on other sites

if you mean that you want the select box to include the names of all your images,

this will work....

 

<?php
$ruff = glob("images/**");

$x = 0;

foreach($ruff as $no => $yea){
$strip = explode("/", $yea);
$content[$x] = $strip[1];
$x++;
}

$y = 0;

foreach($content as $noth => $yup){
$anoth = explode(".", $yup);
$real[$y] = $anoth[0];
$y++;
}

$holder = "          <form name=\"form\" id=\"form\">\n";
$holder .= "<select name=\"jumpMenu\" class=\"dropdown\" id=\"jumpMenu\" onchange=\"MM_jumpMenu('parent',this,0)\">\n";

foreach($real as $file => $name){
$holder .= "\t<option value=\"#\">$name</option>\n";
}

$holder .= "</select>\n";

$holder .= "</form>\n";

echo $holder;

?>

Link to comment
Share on other sites

Na i dnt want the drop down to include images. Just the folder names. Heres what I mean

 

/images/

 

/Holidays/Xmas2007/Family/Boating/

 

So, where i have holidays/xmas..... they will be sub folders (of images) containing images in my root directory. All i need to do is for that drop down to list those folders.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>

<body>
<form name="form" id="form">
        <select name="jumpMenu" class="dropdown" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
   		<option value="#" selected="selected">Browse</option>
        <option value="#">text</option>
  </select>
</form>
</body>
</html>

 

 

Once i get this going ill be set

Link to comment
Share on other sites

Try this

i found the recursive function under the glob docs

http://www.php.net/manual/en/function.glob.php

and adopted it to what you are looking for

 

<?php ob_start();
session_start();

function listdirs($dir) {
    static $alldirs = array();
    $dirs = glob($dir . '/*', GLOB_ONLYDIR);
    if (count($dirs) > 0) {
        foreach ($dirs as $d) $alldirs[] = $d;
    }
    foreach ($dirs as $dir) listdirs($dir);
    return $alldirs;
}

$folder = 'images';
$dirlist = listdirs($_SERVER['DOCUMENT_ROOT'].$folder);

echo <<<htmltext
<form name="form" id="form">
        <select name="jumpMenu" class="dropdown" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
htmltext;
for ($i=0;$i < count($dirlist);$i += 1)
{
echo "<option value=\"".basename($dirlist[$i])."\">".basename($dirlist[$i])."</option>";
}
echo <<<htmltext
  </select>
</form>
htmltext;
?>


Link to comment
Share on other sites

interesting... what is your OS that web server is on, on mine it is Linux

and and so this show the folders i have in my images folder that is one off the root of my site /

if you have no subfolders in the /images folder it will show nothing.

 

if you are on windows then you will need to flip the / to \\

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.