Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- # Include db.inc
- include 'db.inc';
- # Connect to the database
- mysql_connect("$hostName", "$username", "$password");
- ?>
- <html>
- <head>
- <SCRIPT language=JavaScript>
- function reloadpage(form)
- {
- var val=form.icd_main.options[form.icd_main.options.selectedIndex].value;
- self.location='index.php?icd_main=' + val ;
- }
- function reloadpageagain(form)
- {
- var val=form.icd_main.options[form.icd_main.options.selectedIndex].value;
- var val2=form.icd_sub.options[form.icd_sub.options.selectedIndex].value;
- self.location='index.php?icd_main=' + val + '&cat3=' + val2 ;
- }
- </script>
- </head>
- <body>
- <form name="form1" method="post" action="index.php">
- <?php
- # The following code produces the three column drop down list box
- # Get data from category_1 table for first list box
- $quer2=mysql_query("SELECT DISTINCT category,cat_id FROM $databaseName.category_1 order by cat_id");
- # End of query for first list box
- # For second drop down list we will check if a category is selected
- $cat=$HTTP_GET_VARS['icd_main']; // This line is added to take care if global variable is off
- if(isset($cat) and strlen($cat) > 0){
- $quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM $databaseName.subcategory where cat_id=$cat order by subcat_id");
- }
- # For third drop down list we will check if subcategory is selected
- $cat3=$HTTP_GET_VARS['cat3']; // This line is added to take care if global variable is off
- if(isset($cat3) and strlen($cat3) > 0){
- $quer3=mysql_query("SELECT DISTINCT subcat2 FROM $databaseName.subcategory2 where subcat_id=$cat3 order by subcat2");
- }
- # end of query for third subcategory drop down list box
- # Start first drop downlist
- echo "<select name='icd_main' onchange=\"reloadpage(this.form)\"><option value=''>Masina</option>";
- while($noticia2 = mysql_fetch_array($quer2)) {
- # If a category has been selected, show it here
- if($noticia2['cat_id']==@$cat){
- echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";
- }
- # Display all categories
- if($noticia2['cat_id']!=@$cat){
- echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";
- }
- }
- echo "</select>";
- # End first drop down list
- print " ";
- # Start second drop downlist
- echo "<select name='icd_sub' onchange=\"reloadpageagain(this.form)\"><option value=''>Model</option>";
- while($noticia = mysql_fetch_array($quer)) {
- # Display all subcategories for the selected category
- if($noticia['subcat_id']==@$cat3){
- echo "<option selected value='$noticia[subcat_id]'>$noticia[subcategory]</option>"."<BR>";
- }
- # Display all subcategory items
- if($noticia['subcat_id']!=@$cat3){
- echo "<option value='$noticia[subcat_id]'>$noticia[subcategory]</option>";
- }
- }
- echo "</select>";
- # End the second drop down list
- print " ";
- # Start third drop downlist
- echo "<select name='icd_diag'><option value=''>AN</option>";
- while($noticia = mysql_fetch_array($quer3)) {
- echo "<option value='$noticia[subcat2]'>$noticia[subcat2]</option>";
- }
- echo "</select>";
- # End the third drop down list
- ?>
- <input type="submit" value="Arata Produse">
- </form>
- <?php
- # This form handler shows how you could typically handle data from the drop down list boxes.
- # Get values from form
- $icd_main=$_POST['icd_main'];
- $icd_sub=$_POST['icd_sub'];
- $icd_diag=$_POST['icd_diag'];
- # Check to see from which drop down list boxes selections have been made
- # Was an item selected from the third drop down list box?
- if (!$icd_diag){
- # If an item was not selected from the third drop down list box,
- # was one selected from the second?
- if (!$icd_sub){
- # If an item was not selected from the second drop down list box,
- # was one selected from the first?
- # If not, display message
- if (!$icd_main){
- print "";
- }
- else {
- # Select category from category_1 where cat_id = icd_main
- $result = mysql_query(
- "SELECT category FROM $databaseName.category_1 WHERE cat_id = '$icd_main'");
- while ($row = mysql_fetch_assoc($result)){
- $category = $row['category'];
- print "You selected $category from the first drop down list box.\n";
- }
- }
- }
- # If an item was selected from the second drop down list box, make a selection from the
- # subcategory table
- else {
- $result = mysql_query(
- "SELECT subcategory FROM $databaseName.subcategory WHERE subcat_id = '$icd_sub'");
- while ($row = mysql_fetch_assoc($result)){
- $subcategory = $row['subcategory'];
- print "You have selected $subcategory from the second drop down list box.\n";
- }
- }
- }
- # If an item was selected from the third drop down list box
- else {
- print "Ai ales $icd_diag din a treia categorie.\n";
- }
- ?>
- </body>
- </head>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement