Stagnate Posted November 22, 2007 Share Posted November 22, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/ Share on other sites More sharing options...
Northern Flame Posted November 22, 2007 Share Posted November 22, 2007 do you mean you want the drop down list to include a list of all the images? or do you want the drop down list to show the image selected? Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396491 Share on other sites More sharing options...
teng84 Posted November 22, 2007 Share Posted November 22, 2007 since you use jump menu you will also need get variable where you will pass the name or id of each images to be displayed Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396501 Share on other sites More sharing options...
Northern Flame Posted November 22, 2007 Share Posted November 22, 2007 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396504 Share on other sites More sharing options...
Stagnate Posted November 22, 2007 Author Share Posted November 22, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396519 Share on other sites More sharing options...
BenInBlack Posted November 22, 2007 Share Posted November 22, 2007 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396528 Share on other sites More sharing options...
Stagnate Posted November 22, 2007 Author Share Posted November 22, 2007 Ok that one doesnt show the folder names :S closeer I think, though Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396532 Share on other sites More sharing options...
BenInBlack Posted November 22, 2007 Share Posted November 22, 2007 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 \\ Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396536 Share on other sites More sharing options...
Stagnate Posted November 22, 2007 Author Share Posted November 22, 2007 Ok that might do the trick (its XP). I'll give that one a go Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396537 Share on other sites More sharing options...
Stagnate Posted November 22, 2007 Author Share Posted November 22, 2007 Alright money, thats worked . Thanks for your help everone... onto the next issue :S Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396540 Share on other sites More sharing options...
BenInBlack Posted November 22, 2007 Share Posted November 22, 2007 you will have to adjust the path reference in the function also $dirs = glob($dir . '\\*', GLOB_ONLYDIR); Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396541 Share on other sites More sharing options...
Stagnate Posted November 22, 2007 Author Share Posted November 22, 2007 oh yup, seemed to work without doing that but I changed it anyway. Im completely lost for the next part but I think I just need to hit the books Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396545 Share on other sites More sharing options...
BenInBlack Posted November 22, 2007 Share Posted November 22, 2007 books, you don't need waste money on any books, just use these 2 urls http://www.php.net/manual/en/index.php and http://www.google.com (when in google preface your queries with "PHP") Quote Link to comment https://forums.phpfreaks.com/topic/78360-solved-simple-question-about-a-drop-down-list/#findComment-396551 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.