Advertisement
Guest User

Untitled

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