shams Posted July 11, 2018 Share Posted July 11, 2018 (edited) My site will have nearly 2000 html pages, they are grouped in 114 categories each category have many pages, i want to have two dropdown menu in first menu select the category and in the second menu the page to open, i got this code from thesitewizard.com it is working just for one dropdown menu: <form action="chgoto.php" method="get"> <select name="url" onchange="menu_goto(this.form)"> <option value="001_001.html">page 1</option> <option value="001_003.html">page 3</option> <option value="001_005.html">page 5</option> </select> <input type="submit" value="Go!" /> this is chgoto.php: <?php $baseurl = "/" ; $url = $_REQUEST['url'] ; header( "Location: " . $baseurl . $url ); exit ; ?> Edited July 11, 2018 by shams inserting codes tags Quote Link to comment Share on other sites More sharing options...
Barand Posted July 11, 2018 Share Posted July 11, 2018 What is your database structure to control the grouping of pages within category? Quote Link to comment Share on other sites More sharing options...
shams Posted July 11, 2018 Author Share Posted July 11, 2018 I didn't created any database for it, guide me to a link i can do, or if can be possible without any database? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 11, 2018 Share Posted July 11, 2018 What is wrong with the code you posted already? It has only one dropdown and that form and the php in the second block seems to handle the input (despite using the wrong global array to grab the input) correctly. So - what is the problem? Are you simply looking for us to give you the code to build the sub-menus with? What is the JS function supposed to do for you? Is that where you want the sub menu to be shown and get the user's final choice from? Sounds like a use for an ajax call to take the main menu choice and retrieve the sub-menu choices via a php script which returns a json value of those sub-menu choices from which your js code can then build the second drop down with. Is that what you are looking for? Have you tried googling for "ajax call to get sub-menu"? When you use a GET form, you should use the $_GET array to retrieve the expected input(s). When you use a POST form, use the $_POST array for the inputs. This way you cut down on hackers abilities in a fashion. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 11, 2018 Share Posted July 11, 2018 If you don't have a database, what do you have to map pages to category? Quote Link to comment Share on other sites More sharing options...
benanamen Posted July 11, 2018 Share Posted July 11, 2018 Quote My site will have nearly 2000 html pages, they are grouped in 114 categories each category have many pages, ?Red Flag. You need to create a dynamic site. If you do not know how to code, there are may free CMS's available. Wordpress, Drupal, Joomla... To actually create and maintain thousands of static html pages is just asking for a maintenance nightmare. You cant just copy/paste code from some help site. Your options are learn to code, pay someone to do it, or use one of the CMS's available. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 11, 2018 Share Posted July 11, 2018 Take the Profile pages on this site, for example. Do you think someone has created separate html pages for each of the 173,000 members? Quote Link to comment Share on other sites More sharing options...
shams Posted July 12, 2018 Author Share Posted July 12, 2018 Thanks to all, i got the multiple drop down list box code from the plus2net.com, arranged my html pages in a mysql database in table category with columns category id and category name and second table subcategory with category id and their html pages, i select the category from first drop down menu and then it's html page from second drop down menu it prints the category id and it's html page name: Value of $cat = 2 Value of $subcat = 002_001.html how to pass this value to other php code to open this html page? Quote Link to comment Share on other sites More sharing options...
shams Posted July 12, 2018 Author Share Posted July 12, 2018 this is code prints the values: <?php require 'config.php'; // Database connection //////// End of connecting to database //////// ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Multiple drop down list box from plus2net</title> <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='dd.php?cat=' + val ; } </script> </head> <body> <?Php @$cat=$_GET['cat']; // Use this line or below line if register_global is off if(strlen($cat) > 0 and !is_numeric($cat)){ // to check if $cat is numeric data or not. echo "Data Error"; exit; } ///////// Getting the data from Mysql table for first list box////////// $quer2="SELECT DISTINCT category,cat_id FROM category order by category"; ///////////// End of query for first list box//////////// /////// for second drop down list we will check if category is selected else we will display all the subcategory///// if(isset($cat) and strlen($cat) > 0){ $quer="SELECT DISTINCT subcategory FROM subcategory where cat_id=$cat order by subcategory"; }else{$quer="SELECT DISTINCT subcategory FROM subcategory order by subcategory"; } ////////// end of query for second subcategory drop down list box /////////////////////////// echo "<form method=post name=f1 action='dd-check.php'>"; /// Add your form processing page address to action in above line. Example action=dd-check.php//// ////////// Starting of first drop downlist ///////// echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; foreach ($dbo->query($quer2) as $noticia2) { if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";} else{echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";} } echo "</select>"; ////////////////// This will end the first drop down list /////////// ////////// Starting of second drop downlist ///////// echo "<select name='subcat'><option value=''>Select one</option>"; foreach ($dbo->query($quer) as $noticia) { echo "<option value='$noticia[subcategory]'>$noticia[subcategory]</option>"; } echo "</select>"; ////////////////// This will end the second drop down list /////////// //// Add your other form fields as needed here///// echo "<input type=submit value=Submit>"; echo "</form>"; ?> <br><br> <a href=dd.php>Reset and start again</a> <br><br> <center><a href='http://www.plus2net.com' rel="nofollow">PHP SQL HTML free tutorials and scripts</a></center> </body> Quote Link to comment Share on other sites More sharing options...
shams Posted July 12, 2018 Author Share Posted July 12, 2018 Finally the problem solved. Quote Link to comment 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.