Advertisement
Guest User

Untitled

a guest
Aug 13th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <?php
  3.  
  4. # Include db.inc
  5. include 'db.inc';
  6.  
  7. # Connect to the database
  8. mysql_connect("$hostName", "$username", "$password");
  9.  
  10. ?>
  11.  
  12. <html>
  13. <head>
  14.  
  15. <SCRIPT language=JavaScript>
  16.  
  17. function reloadpage(form)
  18. {
  19. var val=form.icd_main.options[form.icd_main.options.selectedIndex].value;
  20. self.location='index.php?icd_main=' + val ;
  21. }
  22.  
  23. function reloadpageagain(form)
  24. {
  25. var val=form.icd_main.options[form.icd_main.options.selectedIndex].value;
  26. var val2=form.icd_sub.options[form.icd_sub.options.selectedIndex].value;
  27.  
  28. self.location='index.php?icd_main=' + val + '&cat3=' + val2 ;
  29. }
  30.  
  31. </script>
  32.  
  33. </head>
  34.  
  35. <body>
  36.  
  37. <form name="form1" method="post" action="index.php">
  38.  
  39. <?php
  40.  
  41. # The following code produces the three column drop down list box
  42.  
  43. # Get data from category_1 table for first list box
  44.  
  45. $quer2=mysql_query("SELECT DISTINCT category,cat_id FROM $databaseName.category_1 order by cat_id");
  46.  
  47. # End of query for first list box
  48.  
  49.  
  50. # For second drop down list we will check if a category is selected
  51.  
  52. $cat=$HTTP_GET_VARS['icd_main']; // This line is added to take care if global variable is off
  53.  
  54. if(isset($cat) and strlen($cat) > 0){
  55. $quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM $databaseName.subcategory where cat_id=$cat order by subcat_id");
  56. }
  57.  
  58. # For third drop down list we will check if subcategory is selected
  59.  
  60. $cat3=$HTTP_GET_VARS['cat3']; // This line is added to take care if global variable is off
  61.  
  62. if(isset($cat3) and strlen($cat3) > 0){
  63. $quer3=mysql_query("SELECT DISTINCT subcat2 FROM $databaseName.subcategory2 where subcat_id=$cat3 order by subcat2");
  64. }
  65.  
  66. # end of query for third subcategory drop down list box
  67.  
  68. # Start first drop downlist
  69.  
  70. echo "<select name='icd_main' onchange=\"reloadpage(this.form)\"><option value=''>Masina</option>";
  71.  
  72. while($noticia2 = mysql_fetch_array($quer2)) {
  73.  
  74. # If a category has been selected, show it here
  75. if($noticia2['cat_id']==@$cat){
  76. echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";
  77. }
  78.  
  79. # Display all categories
  80. if($noticia2['cat_id']!=@$cat){
  81. echo  "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";
  82. }
  83. }
  84. echo "</select>";
  85.  
  86. #  End first drop down list
  87.  
  88. print "&nbsp";
  89.  
  90. #  Start second drop downlist
  91.  
  92. echo "<select name='icd_sub' onchange=\"reloadpageagain(this.form)\"><option value=''>Model</option>";
  93. while($noticia = mysql_fetch_array($quer)) {
  94.  
  95. # Display all subcategories for the selected category
  96. if($noticia['subcat_id']==@$cat3){
  97. echo "<option selected value='$noticia[subcat_id]'>$noticia[subcategory]</option>"."<BR>";
  98.  
  99. }
  100.  
  101. # Display all subcategory items
  102. if($noticia['subcat_id']!=@$cat3){
  103. echo  "<option value='$noticia[subcat_id]'>$noticia[subcategory]</option>";
  104. }
  105. }
  106. echo "</select>";
  107.  
  108. #  End the second drop down list
  109.  
  110. print "&nbsp";
  111.  
  112. # Start third drop downlist
  113. echo "<select name='icd_diag'><option value=''>AN</option>";
  114. while($noticia = mysql_fetch_array($quer3)) {
  115.  
  116. echo  "<option value='$noticia[subcat2]'>$noticia[subcat2]</option>";
  117.  
  118. }
  119. echo "</select>";
  120. # End the third drop down list
  121.  
  122. ?>
  123.  
  124. <input type="submit" value="Arata Produse">
  125.  
  126. </form>
  127.  
  128. <?php
  129.  
  130. # This form handler shows how you could typically handle data from the drop down list boxes.
  131.  
  132.  
  133.  
  134. # Get values from form
  135. $icd_main=$_POST['icd_main'];
  136. $icd_sub=$_POST['icd_sub'];
  137. $icd_diag=$_POST['icd_diag'];
  138.  
  139.   # Check to see from which drop down list boxes selections have been made
  140.  # Was an item selected from the third drop down list box?
  141.  if (!$icd_diag){
  142.  
  143.             # If an item was not selected from the third drop down list box,
  144.             # was one selected from the second?
  145.             if (!$icd_sub){
  146.  
  147.                   # If an item was not selected from the second drop down list box,
  148.                   # was one selected from the first?
  149.  
  150.                   # If not, display message
  151.                   if (!$icd_main){
  152.                       print "";
  153.                   }
  154.  
  155.               else {
  156.               # Select category from category_1 where cat_id = icd_main
  157.  
  158.                 $result = mysql_query(
  159.                 "SELECT category FROM $databaseName.category_1 WHERE cat_id = '$icd_main'");
  160.  
  161.                 while ($row = mysql_fetch_assoc($result)){
  162.                     $category = $row['category'];
  163.                     print "You selected $category from the first drop down list box.\n";
  164.                 }
  165.  
  166.               }
  167.             }
  168.  
  169.             # If an item was selected from the second drop down list box, make a selection from the
  170.             # subcategory table
  171.             else {
  172.  
  173.                 $result = mysql_query(
  174.                 "SELECT subcategory FROM $databaseName.subcategory WHERE subcat_id = '$icd_sub'");
  175.  
  176.                 while ($row = mysql_fetch_assoc($result)){
  177.                     $subcategory = $row['subcategory'];
  178.                     print "You have selected $subcategory from the second drop down list box.\n";
  179.                 }
  180.             }
  181.     }
  182.  
  183.   # If an item was selected from the third drop down list box
  184.     else {
  185.  
  186.            print "Ai ales $icd_diag din a treia categorie.\n";
  187.     }
  188.  
  189.  
  190.  
  191. ?>
  192.  
  193. </body>
  194. </head>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement