geekisthenewsexy Posted September 16, 2010 Share Posted September 16, 2010 hello again,wow this is major prob for me.this is based on the quoted topic above which is already solved (thnks to chipowski!).. anyway the topic solved has 3 dropdowns that gets all the list from a database record. but this time only 2 of those dropdowns gets the list from the database,but the 3 is still connected.ok maybe it's confusing and sorry for the long explanation but i hope someone can help me on this.. it's sort of like this, list 1: course (based on record,(id,course_name)) list 2: yearlevel (not based on record,just a predefined list but it should depend on what course is selected.) list 3: block (based on record,(id,block_name),should depend on the yearlevel selected) i'm deliberating on what to use just to get all three to function,can i use the value on the yearlevel's option value?or something?help? Quote Link to comment Share on other sites More sharing options...
trq Posted September 16, 2010 Share Posted September 16, 2010 What is the problem exactly? Quote Link to comment Share on other sites More sharing options...
geekisthenewsexy Posted September 16, 2010 Author Share Posted September 16, 2010 ok,this is similar to this one: database CREATE TABLE category ( cat_id int(2) NOT NULL auto_increment, category varchar(25) NOT NULL default '', PRIMARY KEY (cat_id) ) TYPE=MyISAM; # # Dumping data for table `category` # INSERT INTO category VALUES (1, 'Fruits'); INSERT INTO category VALUES (2, 'Colors'); INSERT INTO category VALUES (3, 'Games'); INSERT INTO category VALUES (4, 'Vehicles'); # -------------------------------------------------------- # # Table structure for table `subcategory` # CREATE TABLE subcategory ( subcat_id int(3) NOT NULL auto_increment, cat_id int(2) NOT NULL default '0', subcategory varchar(25) NOT NULL default '', UNIQUE KEY subcat_id (subcat_id) ) TYPE=MyISAM;# # Dumping data for table `subcategory` # INSERT INTO subcategory VALUES (1, 1, 'Mango'); INSERT INTO subcategory VALUES (2, 1, 'Banana'); INSERT INTO subcategory VALUES (3, 1, 'Orange'); INSERT INTO subcategory VALUES (4, 1, 'Apple'); INSERT INTO subcategory VALUES (5, 2, 'Red'); INSERT INTO subcategory VALUES (6, 2, 'Blue'); INSERT INTO subcategory VALUES (7, 2, 'Green'); INSERT INTO subcategory VALUES (8, 2, 'Yellow'); INSERT INTO subcategory VALUES (9, 3, 'Cricket'); INSERT INTO subcategory VALUES (10, 3, 'Football'); INSERT INTO subcategory VALUES (11, 3, 'Baseball'); INSERT INTO subcategory VALUES (12, 3, 'Tennis'); INSERT INTO subcategory VALUES (13, 4, 'Cars'); INSERT INTO subcategory VALUES (14, 4, 'Trucks'); INSERT INTO subcategory VALUES (15, 4, 'Blkes'); INSERT INTO subcategory VALUES (16, 4, 'Train'); # -------------------------------------------------------- # # Table structure for table `subcategory2` # CREATE TABLE subcategory2 ( subcat_id int(3) NOT NULL default '0', subcat2 varchar(15) NOT NULL default '' ) TYPE=MyISAM; # # Dumping data for table `subcategory2` # INSERT INTO subcategory2 VALUES (1, 'Mango good'); INSERT INTO subcategory2 VALUES (1, 'Mango bad'); INSERT INTO subcategory2 VALUES (2, 'Banana sweet'); INSERT INTO subcategory2 VALUES (2, 'Banana hot'); INSERT INTO subcategory2 VALUES (3, 'Orange sweet'); INSERT INTO subcategory2 VALUES (3, 'Orange Sour'); INSERT INTO subcategory2 VALUES (4, 'Apple sweet'); INSERT INTO subcategory2 VALUES (4, 'Apple sour'); INSERT INTO subcategory2 VALUES (5, 'Red light'); INSERT INTO subcategory2 VALUES (5, 'Red Zone'); INSERT INTO subcategory2 VALUES (6, 'Blue deep'); INSERT INTO subcategory2 VALUES (6, 'Blue light'); INSERT INTO subcategory2 VALUES (7, 'Green light'); INSERT INTO subcategory2 VALUES (7, 'Green color'); INSERT INTO subcategory2 VALUES (9, 'Cricket Oneday'); INSERT INTO subcategory2 VALUES (9, 'Cricket test'); INSERT INTO subcategory2 VALUES (10, 'Football world'); INSERT INTO subcategory2 VALUES (10, 'Football team'); INSERT INTO subcategory2 VALUES (11, 'Base Ball team'); INSERT INTO subcategory2 VALUES (11, 'Base ball game'); INSERT INTO subcategory2 VALUES (13, 'Cars Big'); INSERT INTO subcategory2 VALUES (13, 'Cars small'); INSERT INTO subcategory2 VALUES (14, 'Trucks Big'); INSERT INTO subcategory2 VALUES (14, 'Trucks small'); INSERT INTO subcategory2 VALUES (15, 'Bikes sports'); INSERT INTO subcategory2 VALUES (15, 'Bike small'); INSERT INTO subcategory2 VALUES (16, 'Train fast'); INSERT INTO subcategory2 VALUES (16, 'Train slow'); INSERT INTO subcategory2 VALUES (8, 'Yellow card'); INSERT INTO subcategory2 VALUES (8, 'Yellow line'); INSERT INTO subcategory2 VALUES (12, 'Tennis Long'); INSERT INTO subcategory2 VALUES (12, 'Tennis table'); as you can see,there are 3 tables that match the lists for the record of the 3 dropdowns,category,subcategory and subcategory2..my problem is, what if the "subcategory" is not in the database only the "category" and "subcategory2"?..i mean subcategory here is already defined,like the values are fixed (e.g.,1,2,3,4,5) so when i click on this menu, it will no longer get its list from the database cuz i already set it's values.. so is it still possible to connect all 3? i mean,subcategory will load depending on the value of category and subcategory2 will load depending on the value of subcategory.. here are the rest of the codes by the way.. <html> <head> <script language="javascript" type="text/javascript"> // Roshan's Ajax dropdown code with php // This notice must stay intact for legal use // Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com // If you have any problem contact me at http://roshanbh.com.np function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function get_subcat(catId) { var strURL="findsubcat.php?catId="+catId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('subcat_div').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } function get_subcat2(subcatId) { var strURL="findsubcat2.php?subcatId="+subcatId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('subcat2_div').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> </head> <body> <form method=post name=f1 action='dd3ck.php'> <div id="first_drop_down"> <select name="catId" onChange="get_subcat(this.value);get_subcat2(0)"> <option>Select one</option> <?php include ('db_connect.php'); $query=("SELECT DISTINCT cat_id, category FROM category order by category"); $result=mysql_query($query); while($row=mysql_fetch_array($result)) { ?> <option value=<?php echo $row['cat_id']?>><?php echo $row['category']?></option> <? } ?> </select> <div id="subcat_div"> <?php include ('findsubcat.php'); ?> </div> <div id="subcat2_div"> <?php include ('findsubcat2.php'); ?> </div> </body> </html> ************************************************************************* Filename: findsubcat.php ************************************************************************* <!--//---------------------------------+ // Developed by Roshan Bhattarai | // http://roshanbh.com.np | // Contact for custom scripts | // or implementation help. | // email-nepaliboy007@yahoo.com | //---------------------------------+--> <? #### Roshan's Ajax dropdown code with php #### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com #### if you have any problem contact me at http://roshanbh.com.np #### fell free to visit my blog http://roshanbh.com.np ?> <? $catId=intval($_GET['catId']); include ('db_connect.php'); if ($catId!=0) { $query="SELECT DISTINCT subcategory,subcat_id FROM subcategory where cat_id='$catId' order by subcategory"; $result=mysql_query($query); } else { $query="SELECT DISTINCT subcategory,subcat_id FROM subcategory order by subcategory"; $result=mysql_query($query); } ?> <select name="subcatId" onchange="get_subcat2(this.value)"> <option>Select one</option> <? while($row=mysql_fetch_array($result)) { ?> <option value=<?=$row['subcat_id']?>><?=$row['subcategory']?></option> <? } ?> </select> ************************************************************************* Filename: findsubcat2.php ************************************************************************* <!--//---------------------------------+ // Developed by Roshan Bhattarai | // http://roshanbh.com.np | // Contact for custom scripts | // or implementation help. | // email-nepaliboy007@yahoo.com | //---------------------------------+--> <? #### Roshan's Ajax dropdown code with php #### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com #### if you have any problem contact me at http://roshanbh.com.np #### fell free to visit my blog http://php-ajax-guru.blogspot.com ?> <? $subcatId=intval($_GET['subcatId']); include ('db_connect.php'); if ($subcatId!=0) { $query="SELECT DISTINCT subcat2 FROM subcategory2 where subcat_id='$subcatId' order by subcat2"; $result=mysql_query($query); } else { $query="SELECT DISTINCT subcat2 FROM subcategory2 order by subcat2"; $result=mysql_query($query); } ?> <select name="subcat2Id"> <option>Select one</option> <? while($row=mysql_fetch_array($result)) { ?> <option value=<?=$row['subcat2']?>><?=$row['subcat2']?></option> <? } ?> </select> 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.