PHP - Which Is The Best Way To Make Dropdown Navigation Menu?
Using unordered list, <ul>
Reading from XML file, Taking menu name from database, Is there other system to make dropdown navigation menu? Which is the best way to make dropdown navigation menu? I also want to show the sitemap of navigation.How can it be done? Similar TutorialsSo i have a <drop down> menu, and a <nav> menu on my left side of the page. I have a problem when i click at the first column of my drop down menu and it explores submenu, the submenu mixes with the nav menu that is under the drop down menu on the left. i could solve it with margin-top of the nav menu but i don't like the empty space beetwen them. I tried with putting overflow:visible; in CSS of my dropdown menu but it is still the same. drop down menu is seen but there is stil seen nav menu under and they are mixed. So basicly i want my dropdown menu to be priority, so when i clicks on my first column (only first column is problem because there under is nav menu the other are open nice) it will explore submenu and the part of nav menu that covers the submenu will be hidden.
Here is the screen shot:
Here is the code of head <dropdown> menu if someone finds the problem.
#menu, #menu ul { margin: 0; padding: 0; list-style: none; } #menu { width: 900px; margin-top:20px; margin-left:auto; margin-right:auto; border: 1px solid #222; background-color: #111; background-image: linear-gradient(#444, #111); border-radius: 6px; box-shadow: 0 1px 1px #777; } #menu:before, #menu:after { content: ""; display: table; } #menu:after { clear: both; } #menu { zoom:1; } #menu li { float: left; border-right: 1px solid #222; box-shadow: 1px 0 0 #444; position: relative; } #menu a { float: left; padding: 12px 30px; color: #999; text-transform: uppercase; font: bold 12px Arial, Helvetica; text-decoration: none; text-shadow: 0 1px 0 #000; } #menu li:hover > a { color: #fafafa; } *html #menu li a:hover { /* IE6 only */ color: #fafafa; } #menu ul { margin: 20px 0 0 0; _margin: 0; /*IE6 only*/ opacity: 0; visibility: hidden; position: absolute; top: 38px; left: 0; z-index: 1; background: #444; background: linear-gradient(#444, #111); box-shadow: 0 -1px 0 rgba(255,255,255,.3); border-radius: 3px; transition: all .2s ease-in-out; } #menu li:hover > ul { opacity: 1; visibility: visible; margin: 0; } #menu ul ul { top: 0; left: 150px; margin: 0 0 0 20px; _margin: 0; /*IE6 only*/ box-shadow: -1px 0 0 rgba(255,255,255,.3); } #menu ul li { float: none; display: block; border: 0; _line-height: 0; /*IE6 only*/ box-shadow: 0 1px 0 #111, 0 2px 0 #666; } #menu ul li:last-child { box-shadow: none; } #menu ul a { padding: 10px; width: 130px; _height: 10px; /*IE6 only*/ display: block; white-space: nowrap; float: none; text-transform: none; } #menu ul a:hover { background-color: #0186ba; background-image: linear-gradient(#04acec, #0186ba); } #menu ul li:first-child > a { border-radius: 3px 3px 0 0; } #menu ul li:first-child > a:after { content: ''; position: absolute; left: 40px; top: -6px; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 6px solid #444; } #menu ul ul li:first-child a:after { left: -6px; top: 50%; margin-top: -6px; border-left: 0; border-bottom: 6px solid transparent; border-top: 6px solid transparent; border-right: 6px solid #3b3b3b; } #menu ul li:first-child a:hover:after { border-bottom-color: #04acec; } #menu ul ul li:first-child a:hover:after { border-right-color: #0299d3; border-bottom-color: transparent; } #menu ul li:last-child > a { border-radius: 0 0 3px 3px; }Here is the code of <nav> menu if someone finds the problem. #cssmenu { width:15%; padding: 0; margin-top: 50px; margin-left:auto; margin right:auto; float:left; border: 0; line-height: 1; } #cssmenu ul, #cssmenu ul li, #cssmenu ul ul { list-style: none; margin: 0; padding: 0; } #cssmenu ul { position: relative; z-index: 597; float: left; } #cssmenu ul li { float: left; min-height: 1px; line-height: 1em; vertical-align: middle; position: relative; } #cssmenu ul li.hover, #cssmenu ul li:hover { position: relative; z-index: 599; cursor: default; } #cssmenu ul ul { visibility: hidden; position: absolute; top: 100%; left: 0px; z-index: 598; width: 100%; } #cssmenu ul ul li { float: none; } #cssmenu ul ul ul { top: -2px; right: 0; } #cssmenu ul li:hover > ul { visibility: visible; } #cssmenu ul ul { top: 1px; left: 99%; } #cssmenu ul li { float: none; } #cssmenu ul ul { margin-top: 1px; } #cssmenu ul ul li { font-weight: normal; } /* Custom CSS Styles */ #cssmenu { width: 200px; background: #333333; font-family: 'Oxygen Mono', Tahoma, Arial, sans-serif; zoom: 1; font-size: 12px; } #cssmenu:before { content: ''; display: block; } #cssmenu:after { content: ''; display: table; clear: both; } #cssmenu a { display: block; padding: 15px 20px; color: #ffffff; text-decoration: none; text-transform: uppercase; } #cssmenu > ul { width: 200px; } #cssmenu ul ul { width: 200px; } #cssmenu > ul > li > a { border-right: 4px solid #1b9bff; color: #ffffff; } #cssmenu > ul > li > a:hover { color: #ffffff; } #cssmenu > ul > li.active a { background: #1b9bff; } #cssmenu > ul > li a:hover, #cssmenu > ul > li:hover a { background: #1b9bff; } #cssmenu li { position: relative; } #cssmenu ul li.has-sub > a:after { content: '+'; position: absolute; top: 50%; right: 15px; margin-top: -6px; } #cssmenu ul ul li.first { -webkit-border-radius: 0 3px 0 0; -moz-border-radius: 0 3px 0 0; border-radius: 0 3px 0 0; } #cssmenu ul ul li.last { -webkit-border-radius: 0 0 3px 0; -moz-border-radius: 0 0 3px 0; border-radius: 0 0 3px 0; border-bottom: 0; } #cssmenu ul ul { -webkit-border-radius: 0 3px 3px 0; -moz-border-radius: 0 3px 3px 0; border-radius: 0 3px 3px 0; } #cssmenu ul ul { border: 1px solid #0082e7; } #cssmenu ul ul a { font-size: 12px; color: #ffffff; } #cssmenu ul ul a:hover { color: #ffffff; } #cssmenu ul ul li { border-bottom: 1px solid #0082e7; } #cssmenu ul ul li:hover > a { background: #4eb1ff; color: #ffffff; } #cssmenu.align-right > ul > li > a { border-left: 4px solid #1b9bff; border-right: none; } #cssmenu.align-right { float: right; } #cssmenu.align-right li { text-align: right; } #cssmenu.align-right ul li.has-sub > a:before { content: '+'; position: absolute; top: 50%; left: 15px; margin-top: -6px; } #cssmenu.align-right ul li.has-sub > a:after { content: none; } #cssmenu.align-right ul ul { visibility: hidden; position: absolute; top: 0; left: -100%; z-index: 598; width: 100%; } #cssmenu.align-right ul ul li.first { -webkit-border-radius: 3px 0 0 0; -moz-border-radius: 3px 0 0 0; border-radius: 3px 0 0 0; } #cssmenu.align-right ul ul li.last { -webkit-border-radius: 0 0 0 3px; -moz-border-radius: 0 0 0 3px; border-radius: 0 0 0 3px; } #cssmenu.align-right ul ul { -webkit-border-radius: 3px 0 0 3px; -moz-border-radius: 3px 0 0 3px; border-radius: 3px 0 0 3px; } Edited by Dorkmind, 26 November 2014 - 05:00 PM. Hi PHP Freaks! Here is my problem. I want to have a PHP navigation system that uses Arrays to control it. Code: [Select] $nav = array( "title1" => "url1", "title2" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title3" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title4" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title5" => "url1", "title6" => "url1" ); $loc = basename($_SERVER["REQUEST_URI"]); What I'm trying to do, is if the $loc is a url in "title4" I want a ul/li printout of that array. Any help you could share with me would be MUCH appreciated. The printout should look like: Code: [Select] <ul> <li>Title4<ul> <li>url1</li> <li>url2</li> </ul></li> </ul> Hi guys! I need a php page that is splitted into 2 screens. One will display the navigation menu and the second one is the iframe. As for the navigation menu, I am getting the list of all files in the current directory with readdir(). Then I create an array with all of the items that are folders (is_dir() function) and apply the same script on them. My problem is to correctly display all of the information I gather in an adequate manner. Can anyone help me with that? Also if anyone has ready-to-go scripts, I would highly appreciate that too. Also, once a user choose a file, it should be loaded in the iframe. How do I specify "src" attribute for the iframe, in that case? Thanks! Hello I need help with making our dropdown links stay visible when active. Site: London tshirt .com Code: [Select] <dl id="nav"> <dt class="nav"><b>London Tshirts</b></dt> <dd> <ul> <li><a href="/Unisex">Unisex</a></li> <li><a href="/Slimfit">Slimfit</a></li> <li><a href="/Kids">Kids</a></li> </ul> </dd> <dt class="nav"><b>Alternative Tshirts</b></dt> <dd> <ul class="nav"> <li><a href="/England">England</a></li> <li><a href="/Humour">Humour</a></li> <li><a href="/Popular">Popular</a></li> </ul> </dd> <dt class="nav"><b>Magnets</b></dt> <dd> <ul class="nav"> <li><a href="/magnets-ceramic">Ceramic</a></li> <li><a href="/magnets-metal">Metal</a></li> <li><a href="/magents-plastic">Plastic</a></li> </ul> </dd> <dt class="nav"><b>Keyrings</b></dt> <dd> <ul class="nav"> <li class="current"><a href="/keyrings-ceramic">Ceramic</a></li> <li class="current"><a href="/keyrings-metal">Metal</a></li> <li><a href="/keyrings-plastic">Plastic</a></li> </ul> </dd> <dt class="nav"><b>Other gifts</b></dt> <dd> <ul class="nav"> <li><a href="/Hats">Hats</a></li> <li><a href="/Models">Models</a></li> <li><a href="/Bags">Bags</a></li> </ul> </dd> </dl> Thanks P.S. I typed my question, then went to verification, but could not read the letters so requested a new image, this refreshed the page and I lost my message?? In CSS, most people add most styling to the A tag instead of UL or LI. Do you know why?
Hi all. I'm working on a project that requires a 3 tier navigation menu that's dynamic and I'm not quite sure where to start with it. The structure of the menu is like so... A unique list of Parent-Modules Tier1: Parent-Module1 Each parent module has a second tier menu that appears upon clicking a parent module. Each parent module has a unique list of tier 2 sub modules Tier 2: Sub-Module1 - Sub-Module2 Each sub module has a third tier menu that appears upon clicking a sub module. Each sub module has a unique list of tier 3 child modules Tier 3: Child-Module1 - Child-Module2 - Child-Module3 A visual: Parent (each parent module has this structure) | |--------Sub Module | |-Child Module 1 | |-Child Module 2 | |-Child module 3 |--------Sub Module | |-Child Module 1 | |-Child Module 2 | |-Child module 3 |--------Sub Module |-Child Module 1 |-Child Module 2 |-Child module 3 Every tier has to be dynamic as the module names/locations are often changed. My thought is to use opendir/readdir in order to build the tiers based on what files exist, but I'm not sure if this is a safe/reliable practice. Any input would be a great help. EDIT: The navigation links would have to have "pretty" names (e.g. Business Processes instead of business_processes). Code: [Select] <div id="nav"> <ul> <li class="item"><a href="/">Home</a>/</li> <li class="item"><a href="/one">one</a></li> <li class="item"><a href="/two>two</a></li> <li class="item"><a href="/three">three</a></li> </ul> <div> i want to add class='active' to the a tags . when the menu is the current page. namely.when i on the home page. the a label is Code: [Select] <li class="item"><a href="/" class="active">Home</a>/</li> .but the others a label are not have class="active". when i on the one page. it is is Code: [Select] <li class="item"><a href="one" class="active">one</a>/</li>.the others a label are not have class="active". Hi i have a online/offline script that works great no issues at all. In order to change the html, php file to display when offline I need to point it to that file via input field. What i would like is to change the input filed and have a dropdown that list all the folders and subfolders within the the directory where all the templates are located. I have found a php snippet on the forum that does exactly what i want. The issue is now is to remove the input filed in the script and insert the snippet found here and thats where the issue comes. I'm hoping some guru here can easily help me out . please see below for the code online/offline code ( input filed i would like to replace with dropdown selector <input type="text" name="txttemplate" value="%s" id="txttemplate" />) Code: [Select] <?php session_start(); $page_offline = TRUE; $page_offline_title = " "; $page_offline_message = " Offline"; $admin_ip = "1.1.1.1"; $admin_password = "*****************"; $page_offline_template = "template/path/index.php"; $page_offline_foradmin = TRUE; ini_set("display_errors", "0"); error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR); $page = strstr($_SERVER['PHP_SELF'], "off.php") ? "admin" : "website"; // Try login $login_error = FALSE; if(isset($_POST['txtpassword'])){ if(md5($_POST['txtpassword']) == $admin_password){ $_SESSION['offline_admin'] = TRUE; }else{ $login_error = TRUE; } } // Save config settings $offline = $page_offline ? 'checked="checked"' : ""; $title = $page_offline_title; $message = $page_offline_message; $saved = FALSE; $template = $page_offline_template; $adminoffline = $page_offline_foradmin ? 'checked="checked"' : ""; if(isset($_POST['btnsave']) && $_SESSION['offline_admin']){ $val_offline = isset($_POST['chkoffline']) && ($_POST['chkoffline'] == "true") ? TRUE : FALSE; $val_title = htmlspecialchars($_POST['txttitle']); $val_message = htmlspecialchars($_POST['txtmessage']); $val_template = htmlspecialchars($_POST['txttemplate']); $val_password = htmlspecialchars($_POST['txtpassword']); $val_adminoffline = isset($_POST['chkconstruct']) && ($_POST['chkconstruct'] == "true") ? TRUE : FALSE; $offline = $val_offline ? 'checked="checked"' : ""; $title = $val_title; $message = $val_message; $template = $val_template; $adminoffline = $val_adminoffline ? 'checked="checked"' : ""; if(empty($val_password)){ page_offline_save($val_offline, $val_title, $val_message, $val_template, $adminoffline); }else{ page_offline_save($val_offline, $val_title, $val_message, $val_template, $adminoffline, $val_password); } $saved = TRUE; } // Templates $admin_style_tpl = <<<ADMINSTYLETPL body{ font-family:Arial, Helvetica, sans-serif; font-size:11px; text-align: center; background-color:#F9F9F9; color:#555555; } #wrapper{ width:400px; padding:20px; margin: 0 auto; border:1px solid #DADADA; background-color: #FFF; text-align: left; } h2{ margin: 0px 0px 10px 0px; padding: 0px; font-size: 24px; color:#464646; font-family:Georgia,"Times New Roman",Times,serif; font-style: italic; font-weight: normal; } label{ display: block; width: 150px; font-weight: bold; padding: 14px 0px 3px 0px; } input{ -moz-border-radius-bottomleft:3px; -moz-border-radius-bottomright:3px; -moz-border-radius-topleft:3px; -moz-border-radius-topright:3px; width: 300px; background:#F5F5F5 none repeat scroll 0 0; border:1px solid #CCCCCC; color:#666666; padding: 4px 8px; } #chkoffline, #chkconstruct{ width: 20px; } .error{ border: solid 1px #CC0000; } ADMINSTYLETPL; $admin_login_tpl = <<<ADMINLOGINTEMPLATE <!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>Login</title> <style> %s </style> </head> <body> <div id="wrapper"> <h2>Login</h2> <form id="form1" name="form1" method="post" action=""> <label for="txtpassword">Password</label> <input type="password" name="txtpassword" %s id="txtpassword" /><br /><br /> <input name="btnlogin" type="submit" value="Login" /> </form> </div> </body> </html> ADMINLOGINTEMPLATE; $admin_config_tpl = <<<ADMINCONFIGTEMPLATE <!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></title> <style> %s </style> </head> <body> <div id="wrapper"> <h2></h2> <form id="frmadmin" name="frmadmin" method="post" action=""> <label for="chkoffline">Offline</label> <input name="chkoffline" id="chkoffline" %s type="checkbox" value="true" /> <label for="chkconstruct">Show offline to admin</label> <input name="chkconstruct" id="chkconstruct" %s type="checkbox" value="true" /> <label for="txttitle">Title</label> <input type="text" name="txttitle" value="%s" id="txttitle" /> <label for="txtmessage">Message</label> <input type="text" name="txtmessage" value="%s" id="txtmessage" /> <label for="txttemplate">Template</label> <input type="text" name="txttemplate" value="%s" id="txttemplate" /> <label for="txtpassword">Admin password</label> <input type="password" name="txtpassword" id="txtpassword" /> <br /> Leave this field empty if you don't want to change the admin password. <br /><br /> <input name="btnsave" type="submit" value="Save" /> </form> </div> </body> </html> ADMINCONFIGTEMPLATE; $admin_saved_tpl = <<<ADMINSAVEDTEMPLATE <!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>Offline Admin</title> <style> %s </style> </head> <body> <div id="wrapper"> <h2>Configuration saved</h2> The configuration is saved succesfully. You can continue to <a href="off.php">config</a> or go to your <a href="../">Homepage</a> or back to <a href="index.php">admin panel</a>. </div> </body> </html> ADMINSAVEDTEMPLATE; if($page == "admin"){ // If user not is loggedin then show login screen if(!isset($_SESSION['offline_admin']) || !$_SESSION['offline_admin']){ echo sprintf($admin_login_tpl, $admin_style_tpl, ($login_error) ? 'class="error"' : ''); }else{ if(!$saved){ echo sprintf($admin_config_tpl, $admin_style_tpl, $offline, $adminoffline, $title, $message, $template); }else{ echo sprintf($admin_saved_tpl, $admin_style_tpl); } } exit(); }else{ if($page_offline && (($_SERVER['REMOTE_ADDR'] != $admin_ip) || $page_offline_foradmin)){ ob_start(); include($page_offline_template); $template = ob_get_contents(); ob_end_clean(); // Replace variables $template = str_replace(array("{TITLE}", "{MESSAGE}"), array($page_offline_title, $page_offline_message), $template); // Show template echo $template; exit(); } } // Write settings to file function page_offline_save($offline, $title, $message, $template, $adminoffline, $password=""){ $lines = explode("\n", file_get_contents("offline.php")); // Set configuration $offline_state = ($offline) ? "TRUE" : "FALSE"; $lines[2] = '$page_offline = ' . $offline_state . ';'; $lines[3] = '$page_offline_title = "' . $title . '";'; $lines[4] = '$page_offline_message = "' . $message . '";'; $lines[5] = '$admin_ip = "' . $_SERVER['REMOTE_ADDR'] . '";'; $lines[7] = '$page_offline_template = "' . $template . '";'; $adminoffline_state = ($adminoffline) ? "TRUE" : "FALSE"; $lines[8] = '$page_offline_foradmin = ' . $adminoffline_state . ';'; if(!empty($password)){ $lines[6] = '$admin_password = "' . md5($password) . '";'; } // Save to file file_put_contents("off.php", implode("\n", $lines)); } ?> snippet found here on the forum Code: [Select] <?php $parent_directory = 'path/to/directory'; $file_types = 'html,htm,php,etc'; //===================================================// // FUNCTION: directoryToArray // // // // Parameters: // // - $root: The directory to process // // - $to_return: f=files, d=directories, b=both // // - $file_types: the extensions of file types to // // to return if files selected // //===================================================// function directoryToArray($root, $to_return='b', $file_types=false) { $array_items = array(); if ($file_types) { $file_types=explode(',',$file_types); } if ($handle = opendir($root)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $add_item = false; $type = (is_dir($root. "/" . $file))?'d':'f'; $name = preg_replace("/\/\//si", "/", $file); if ($type=='d' && ($to_return=='b' || $to_return=='d') ) { $add_item = true; } if ($type=='f' && ($to_return=='b' || $to_return=='f') ) { $ext = end(explode('.',$name)); if ( !$file_types || in_array($ext, $file_types) ) { $add_item = true; } } if ($add_item) { $array_items[] = array ( 'name'=>$name, 'type'=>$type, 'root'=>$root); } } } // End While closedir($handle); } // End If return $array_items; } if (isset($_POST[pickfile])) { // User has selected a file take whatever action you want based // upon the values for folder and file } else { echo ' <html> <head> <script type="text/javascript"> function changeFolder(folder) { document.pickFile.submit(); } </script> </head> <body>'; echo "<form name=\"pickFile\" method=\"POST\">\n"; $directoryList = directoryToArray($parent_directory,'d'); echo "<select name=\"folder\" onchange=\"changeFolder(this.value);\">\n"; foreach ($directoryList as $folder) { $selected = ($_POST[folder]==$folder[name])? 'selected' : ''; echo "<option value=\"$folder[name]\" $selected>$folder[name]</option>\n"; } echo '</select><br><br>'; $working_folder = ($_POST[folder]) ? $_POST[folder] : $directoryList[0][name]; $fileList = directoryToArray($parent_directory.'/'.$working_folder,'f',$file_types); echo "<select name=\"file\">\n"; foreach ($fileList as $file) { echo "<option value=\"$file[name]\">$file[name]</option>\n"; } echo '</select><br><br>'; echo "<button type=\"submit\" name=\"pickfile\">Submit</button>\n"; echo "</form>\n"; echo "</body>\n"; echo "</html>\n"; } ?> Thank you in advance for any help... Hi all, I was wondering if someone knows a clean way to make a dropdown menu using just php and html with the following functionality. If someone selects a value from the dropdown options it should be visible on refresh. So in case a have a dropdown menu with: oranges, apples, grapes and someone selects grapes and submits it, grapes should be selected. I have made someonthing but it looks redundant. I think there should be something with a foreach loop or something but i can't figure it out yet. Thanks in advance, cheers!! I want make the following, (I have already a database with three tables (Countries, Timeline and Category)). 1: list of countries (drop down menu 1), Timeline of the countries history (drop down 2) and Category (drop down 3). 2: The selected values of the drop down menus must show take the information from the database. Can any one help me with the coding? I think after a lot of trouble I've finally managed to get my hierarchical php driven hierarchical dropdown menu working. I now have 1 problem with it which I simply can't figure out. Rather than explain this I think a picture is worth a thousand words so here's the script in action:- http://www.coolvisiontest.com/garyssite/rhrvouchers/menu4.php If you notice in that example when you hover over categories then level1a then level2a the menu's and their children appear 1 at a time as they should. However if you hover over level1a then level2b then all at once all of the child categories of 2b and all of their child catagories and their child categories etc appear at once rather than one at a time. You should have to hover over level3e to see level4a and you should have to hover over level4a to see level5a etc. The code I have is a combination of 2 sets of code I came across to be honest so I'm having trouble figuring it out. At the moment I only have 3 problems with it:- 1. I only want subcategories to be shown when their parent category is hovered over as explained above 2. I only want the bottom level of categories to act as links e.g. levels 2c 3a 3b 3c 3d and 5a would act as links in this example as they are the last of all the children, the rest of the categories should be plain text. I'm not sure if this is achievable though as I think links are required for the hover functionality. 3. I want some way of indicating to the user that a category has children perhaps by including a little right arrow or plus sign and of course this should only be included for the categories that have children and not the others. Can anyone help me out with these three things please? Here's my code so far:- <?php $link = mysqli_connect('localhost','',''); mysqli_select_db($link,''); $query = mysqli_query($link,'SELECT * FROM nested_categories'); while ( $row = mysqli_fetch_assoc($query) ){ $menu_array[$row['id']] = array('id' => $row['id'],'name' => $row['name'],'parent' => $row['parent_id']); } function generate_menu($parent){ $has_childs = false; global $menu_array; foreach($menu_array as $key => $value){ if ($value['parent'] == $parent){ if ($has_childs === false){ $has_childs = true; echo '<ul>'; } echo '<li><a href="menu4.php?id='.$value['id'].'">'.$value['name'].'</a>'; generate_menu($key); echo '</li>'; } } if ($has_childs === true) echo '</ul>'; } ?> <div id="menu"> <ul> <li><h2>categories</h2> <?php generate_menu(0); ?> </li> </ul> </div> And the Css:- #menu { width: 100%; background: #eee; float: left; } #menu ul { list-style: none; margin: 0; padding: 0; width: 12em; float: left; } #menu a, #menu h2 { font: bold 11px/16px arial, helvetica, sans-serif; display: block; border-width: 1px; border-style: solid; border-color: #ccc #888 #555 #bbb; margin: 0; padding: 2px 3px; } #menu h2 { color: #fff; background: #000; text-transform: uppercase; } #menu a { color: #000; background: #efefef; text-decoration: none; } #menu a:hover { color: #a00; background: #fff; } #menu li {position: relative;} #menu ul ul { position: absolute; z-index: 500; } #menu ul ul ul { top: 0; left: 100%; } div#menu ul ul, div#menu ul li:hover ul ul, div#menu ul ul li:hover ul ul {display: none;} div#menu ul li:hover ul, div#menu ul ul li:hover ul, div#menu ul ul ul li:hover ul {display: block;} hello everybody..
i need help..
i want to make a dropdown menu with php coding that will show the result from my database.. can anyone help me to generate the coding?
this is an example form:
<form action="" method="get"><select name=""> <option value="select">select</option> <option value="1">1 </option> <option value="2">2</option> <option value="3">3</option> </select> <label> <input type="submit" name="button" id="button" value="Submit" /> </label> </form> if user select 1, the php code will show a list of name by their identification card, if user select 2 the php code will show a list of name by country. Hi, I don't know if this is the right place, but I used a code for a dropdown menu witch works fine on the website (geloven.eu/ABK2021) who uses PHP 7.2.24, but the dropdown does NOT work on another site bijbelkamp.eu/ABK2021 who uses PHP 7.3.28. The index page just includes the menu.php (here menu.txt) and the css file bootstrap21.css (here bootstrap21.txt). Can this be some coding issue or does this have nothing to do with the code? bootstrap21.txt menu.txt Hello,
I'm new to php, I don't really have much experience, just have used it in combination with dreamweaver. I'm tackling a new problem now.
Basically, it's about a dropdown menu with pre-defined values. There are multiple dropdowns, having different value choices. People are supposed to be able to select more than one option and then search for the results. these should then be generated according to the selected values, or if no value is selected, ALL is shown.
When the user clicks on search, the values create a msql query that will then be executed and the results shown on the page.
I've been searching high and low for code ideas, but see different stuff everywhere I look, and none of the code seems to be what i want. Some people are using Javascript, some Ajax, or PHP. ideally, I want to use just php and sql
Can someone point me in the right direction on how to tackle this problem, or maybe someone has some code ideas?
Thanks in advance.
Mio
how do i this? i have no idea....i need to incorporate it on an html form pleas help? i will get the data from this line and must be able to select one from the dropdown and get the id/name from the one selected [COLOR="Red"]$supplier_names = LpmAdnetworkPeer::getByName($catcher_id);[/COLOR] thank you Hi, I'm trying to get data from one field in a table (database). But I get undesirable result: Here is my code -> <?php $result2 = mysql_query("SELECT DISTINCT theme FROM mytable ") or die(mysql_error()); while($row2 = mysql_fetch_array( $result2 )) { ?> <form method="post" action='<?php echo $_SERVER["PHP_SELF"]; ?>'> <select name='themes'"> <?php $arr= array($row2['theme']); foreach($row2 as $value) { echo "<option value='$value'><b>". $value."</b> </option><br> "; } } ?> The attached image file show the result that I don't wont. (It's not a dropdown). Is there anyone who may help me, I spent a lot of time to find out but I can't. Thanks a lot for your help This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=333787.0 I have a dropdown menu in a form where users must select their instrument: here's the dropdown: Code: [Select] <label for="instrument"><span class='red'>*</span>Your main instrument</label> <select name="instrument" id="instrument"> <option value="select" selected="selected">Select your instrument…</option> <option value="bassoon">Bassoon</option> <option value="cello">Cello</option> <option value="clarinet">Clarinet</option> <option value="double_bass">Double Bass</option> <option value="flute">Flute</option> <option value="french_horn">French Horn</option> <option value="oboe">Oboe</option> <option value="percussion">Percussion</option> <option value="trombone">Trombone</option> <option value="trumpet">Trumpet</option> <option value="tuba">Tuba</option> <option value="viola">Viola</option> <option value="violin">Violin</option> <option value="other">Other</option> </select> I want to validate to ensure that the user has selected an instrument from the list. I was going to do something like this: Code: [Select] // validate for instrument selection if(!isset($_POST['instrument'])) { $serrors[] = 'Please select your instrument.'; } else { $_SESSION['instrument'] = $_POST['instrument']; } The problem is, the session variable gets set if the user bypasses the menu altogether, leaving the default 'Select your instrument...' option (at the top) as it is. How can I ensure a selection other than the 'Select your instrument...' at the top of the list? Thanks in advance. Some forum users here gave me great help yesterday in working with dropdown menus. In fact, I need quite a few of these dropdown menus in several forms over several pages, so I created several simple arrays and made a function to create the dropdowns. Here's one of my arrays: Code: [Select] <?php $instruments = array( 'Bassoon', 'Cello', 'Clarinet', 'Double Bass', 'Flute', 'French Horn', 'Oboe', 'Percussion', 'Trombone', 'Trumpet', 'Tuba', 'Viola', 'Violin', 'Other' ); Here's my function: Code: [Select] <?php function create_dropdown($array_name, $array_item) { echo "<select name='$array_item'>\n"; echo "<option value='select'>Select…</option>\n"; foreach( $array_name as $v ) { echo "<option value='$v'>" . $v . "</option>\n"; } echo "</select>\n"; } ... and anywhere I need a dropdown menu, I'm calling it like this: Code: [Select] <?php create_dropdown($instruments, 'instrument'); The dropdown menus, however (in some fairly detailed forms for my local youth orchestra's site), need to be sticky. How can I modify my function, above, so that the selected value will be retained if there are other form submission errors when the form is submitted? I have tried endlessly today but to no avail... If you can help while I still have some hair left, I'd be greatly appreciative. I'm attempting to create a dropdown hover menu by following the instructions on the Suckerfish site. The list that is supposed to dropdown simply stays visible all the time. Is there anything in the code that seems to be the apparent cause of the problem? You will be able to tell that I'm new to PHP. Any suggestions would be appreciated. The following is my CSS and PHP code: CSS: Code: [Select] #nav, #nav ul{ padding: 0; margin: 0; list-style: none; } #nav a{ display: block; width: 10em; } #nav li{ float: left; width: 10em; } #nav li ul{ position: absolute; width: 10em; left: -999em; } #nav li: hover ul{ left: auto; } #nav li:hover ul, #nav li.sfhover ul{ left: auto; } PHP/JavaScript: Code: [Select] function draw_app_menu() { // draw the application menu ?> <!-- left - background-color: #cdeb8b - lime --> [color=blue]<script type="text/javascript"> shHover = function() { var sfEls = document.getElementByID("nav").getElementsByTagName("LI"); for (var i=0; i<sfEls.length;i++) { sfEls[i].onmouseover=function() { this.className+=" sfhover"; } sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } } } if (window.attachEvent) window.attachEvent("onload",sfhover); </script>[/color] [color=green]<ul id = "nav">[/color] <?php session_start(); if (isset($_SESSION['selected_app'])) { // echo '<p> selected_app was set </p>'; foreach ($_SESSION['application_list'] as $app_list) { if (($app_list[5] == 'A') && ($app_list[0] == $_SESSION['selected_app'])) { $_SESSION['current_link'] = $app_list[2]; } if (($app_list[0] == $_SESSION['selected_app']) && (($app_list[5] == 'M') || ($app_list[5] == 'S'))) { if ($app_list[5] == 'M') { ?> [color=green]<li><a href="<?php echo $_SESSION['current_link'].'?id='.$_SESSION['selected_app'].'&modid='.$app_list[3].'&func='.$app_list[6];?>"><?php echo $app_list[1];?></a></li>[/color] <?php $_SESSION['selected_mod'] = $_GET['modid']; $_SESSION['app_function'] = $_GET['func']; } ?> [color=green] <ul>[/color] <?php if ($app_list[5] == 'S') { ?> [color=green]<li><a href="<?php echo $_SESSION['current_link'].'?id='.$_SESSION['selected_app'].'&modid='.$app_list[3].'&submodid='.$app_list[4].'&func='.$app_list[6];?>"><?php echo $app_list[1];?></a></li>[/color] <?php $_SESSION['selected_mod'] = $_GET['modid']; $_SESSION['selected_submod'] = $_GET['submodid']; $_SESSION['app_function'] = $_GET['func']; } ?> [color=green]</ul> </li>[/color] <?php } } } ?> [color=green]</ul>[/color] <script src="sfhover.js" type="text/javascript"></script> <?php } |