PHP - Search Records By Dropdown Menu
Hello I am having a trouble with creating page that will search records from database using dropdown menu, when I select a category, for example By: Gender and after clicking the Submit button, there is no records displays but when I select By: ALL, the records displays. What's wrong with my code? I'm sorry I'm fairly new to PHP. Here is my code:
Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Search</title> </head> <body> <form action="" method="POST" name="records"> <label>SEARCH: </label> <select name="select"> <option value="all" selected="selected">ALL</option> <option value="year">By Year</option> <option value="gender">By Gender</option> <option value="course">By Course</option> </select> <input name="submit" value="GO" type="submit" /> <br /> </form> </body> </html> <?php include('collegeinfo_connect.php'); mysql_connect("$server", "$user", "$pass")or die("cannot connect"); mysql_select_db("$db")or die("cannot select DB"); if (isset($_POST['submit'])) { $selection = $_POST['select']; if($selection == "all") $query = "SELECT * FROM collegeinfo_tbl"; else if($selection == "year") $query = "SELECT * FROM collegeinfo_tbl WHERE Year='year'"; else if($selection == "gender") $query = "SELECT * FROM collegeinfo_tbl WHERE Gender='gender'"; else if($selection == "course") $query = "SELECT * FROM collegeinfo_tbl WHERE Course='course'"; } if (isset($query)) { $result = mysql_query($query) or die(mysql_error()); echo "<br /> <br />"; echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>ID Number:</th> <th>First Name:</th> <th>Last Name:</th> <th>Gender:</th> <th>Year:</th> <th>Course:</th> </tr>"; while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td>' . $row['ID'] . '</td>'; echo '<td>' . $row['FirstName'] . '</td>'; echo '<td>' . $row['LastName'] . '</td>'; echo '<td>' . $row['Gender'] . '</td>'; echo '<td>' . $row['Year'] . '</td>'; echo '<td>' . $row['Course'] . '</td>'; echo "</tr>"; } echo "</table>"; } ?> Similar TutorialsThis topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=353763.0 I wonder whether someone can help me please. I've found http://www.plus2net.com/php_tutorial/ajax-listbox.php tutorial to create a drop down menu using mySQL table data, which, in turn returns a list of results on the page. Following this tutorial I've put together the tables in my database and the required scripts as shown in the tutorial with the one exception, the "z_db.php" file, which I've assumed to be: Code: [Select] <?php mysql_connect("host", "user", "password")or die(mysql_error()); mysql_select_db("database"); ?> The problem I have, is that when I try and run this, I receive the following error: Quote Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /homepages/2/d333603417/htdocs/development/catsearch.php on line 91 which is this line in the search form: echo "</head><body onload="ajaxFunction()";>";. I must admit I've guessed as to the structure of the 'z_db.php' file should look like because this is not shown so perhaps this is the problem. I just wondered wether someone could perhaps take a look at this please and let me know where I've gone wrong. Many thanks and kind regards Hey All. I'm trying to modify a search I have setup. What I want to do is take out the text field and replace it with a dropdown menu. It starts with an html form Old working code: Code: [Select] <form action="result.php" method="post"> <div align="center">Search: <input type="text" name="search" /> <input type="submit" /> </div> </form> New non working code: Code: [Select] <form action="result.php" method="POST"> <select name="dropdown"> <option value="option1">option1</option> <option value="option2">option2</option> <option value="option3">option3</option> </select><input type="submit" name="search" /> </form> That should open up result.php which searches two fields in a mysql database and prints of the results. result.php Code: [Select] $var = $_POST["search"]; $data = mysql_query("select * FROM database1 WHERE field1 LIKE '$var' || field2 LIKE '$var'") or die(mysql_error()); echo $data; ?> If result.php not receiving the info in the dropdown or am I handling it wrong in the php? Thanks so much. hi, im new to php and need some help with my project. i wanted to create a search form with dropdown list provided that the values in the dropdown list are the field names of the database that the form that call the search form. Ex. i have a A.php form that uses Table A from database X. then A.php press a button inside the form and then a search form will show. when i search for something in that table the dropdownlist will be populated by the field names of Table A. this same goes to B.php that uses Table B of database X.. and so on.. can anyone help me with this?? thanks!! Hi, I have a search form where users can search by age and country. Users can also save their search so they can go back and do it again but the problem is when they reload their saved search, I need it to select the country that has been saved in the drop down. So if someone searched the United Kingdom, I need it to show United Kingdom in the select drop down instead of (Select Country). Is there any easy and quick way around this? Many Thanks So 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. I am having trouble showing reports for a given date range. Currently if I specify something like 11/03/2010 to 11/05/2010 I get results for all years within that month and day such as I may get results for 11/03/2008 11/03/2009 11/03/2010 11/04/2008 11/04/2009 11/04/2010 11/05/2008 11/05/2009 11/05/2010. I am using the following code $result = mysql_query("SELECT * FROM report WHERE date>='$date_begin' and date<='$date_end' ORDER BY 'date'",$db); I use the following format in my date feild mm/dd/yyyy My script is finally working as intended, but I want to add some additional data results. I am trying to resolve how I can display a count of ONLY the records updated by my query: // START :: Query to replace matches mysql_query("UPDATE orig_codes_1a AS a JOIN old_and_new_codes_1a AS b ON concat(a.orig_code_1, a.orig_code_2) = concat(b.old_code_1, b.old_code_2) SET a.orig_code_1 = b.new_code_1, a.orig_code_2 = b.new_code_2") or die(mysql_error()); // END :: Query to replace matches In this query I count ALL records selection: // START :: Create query to be displayed as final results of original codes table. $result = mysql_query("SELECT * FROM orig_codes_1a") or die(mysql_error()); I want to display a count on this part of the query: ....concat(a.orig_code_1, a.orig_code_2) = concat(b.old_code_1, b.old_code_2).... 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!! 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 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. 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;} 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
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? 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 I'm not sure what to search for or if this can be done... Let's say I have a mysql table named "genre". Now I have "Male" and "Female" in a dropdown menu like this in a form: <select name="genre"> <option>Male</option> <option>Female</option> </select> How would you display, for example, the option Female in a update.php file if that's the genre stored in the mysql database when you fetch the results? |