New MySQL Question. Grouping

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #16
    Just looking at the code and trying to find oddities. Just 40 yrs experience.

    Now that you have changed all this code, I can no longer follow what has been changed and what not.

    Ronald :cool:

    Comment

    • Chrisjc
      Contributor
      • Nov 2006
      • 375

      #17
      Originally posted by ronverdonk
      Just looking at the code and trying to find oddities. Just 40 yrs experience.

      Now that you have changed all this code, I can no longer follow what has been changed and what not.

      Ronald :cool:

      here is the update.... for INDEX.PHP

      Code:
      <html><head><title>aFe Catalog Test v3</title>
      </style>
      <script type="text/javascript" src="ajax/ajax.js"></script>
      <script type="text/javascript">
      var ajax = new sack();
      var selYear;
      var selMake;
      var selModel;
      function getMake(sel) {
          selYear = sel.options[sel.selectedIndex].value;
          if(selYear.length>0){
              ajax.requestFile = 'getsearch.php?getmake=1&year='+selYear;    // Specifying what to get
              ajax.onCompletion = createDropdownMake;    // Specify function that will be executed after file has been found
              ajax.runAJAX();        // Execute AJAX function
          }
      }
      function createDropdownMake() {
          document.getElementById("divmsg").innerHTML = ajax.response;
      }  
          function getModel(sel) {
          selMake = sel.options[sel.selectedIndex].value;
          if(selMake.length>0){
              ajax.requestFile = 'getsearch.php?getmodel=1&make='+selMake+'&year='+selYear;    // Specifying what to get
              ajax.onCompletion = createDropdownModel;    // Specify function that will be executed after file has been found
              ajax.runAJAX();        // Execute AJAX function
          }  
      }
      function createDropdownModel() {
          document.getElementById("divmsg").innerHTML = ajax.response; 
      }
      function getDesc(sel) {
          selModel = sel.options[sel.selectedIndex].value;
          if(selModel.length>0){
              ajax.requestFile = 'getsearch.php?getdesc=1&model='+selModel'&=make'+selMake+'&year='+selYear;    // Specifying what to get
              ajax.onCompletion = createDesc;    // Specify function that will be executed after file has been found
              ajax.runAJAX();        // Execute AJAX function
          }
      }
      function createDesc() {
          document.getElementById("divmsg").innerHTML = ajax.response;    
      }
      </script>
      </head>
      <body>
      <?php
      // ==================================================  ===
      //  Populate the YEARS selection list from the database
      // ==================================================  ===
      echo '<u><b>aFe Vehicle Search Browser v3</b></u>
      <form action="" method="post">
         Select year:&nbsp;&nbsp;&nbsp;
         <select id="years" name="years" style="width: 170" onchange="getMake(this)">
           <option value="">Select</option>';
      // Connection to the Database
      include ('db functions/db_connect.php');
      $res = mysql_query("SELECT year FROM Catalog GROUP BY year ORDER BY year DESC")
         or die("Invalid query: " . mysql_query());
      while ($row = mysql_fetch_assoc($res)) {
         $yr = $row['year'];
         echo "<option value=$yr>$yr</option>";
      }
      echo '</select>';
      ?>
           <div id="divmsg" />
           
      </form>
      </body></html>
      and for getserach.php

      Code:
      <?php  
      // Connection to the Database
      include ('db functions/db_connect.php');
      // Get the make after user searched year.
      if(isset($_GET['getmake'])  AND  isset($_GET['year'])){   
        $yr = $_GET['year']; 
        $res = mysql_query("SELECT make FROM Catalog WHERE year=$yr GROUP BY make ORDER BY make")
           or die("Invalid query: " . mysql_query());     
        echo 'Select make:&nbsp;&nbsp;';
        echo '<select id="make" name="make" style="width: 170" onchange="getDesc(this)">';
        echo '<option value="">Select</option>';
        while ($row = mysql_fetch_assoc($res)) {
           $mk = $row['make']; 
           echo "<option value=$mk>$mk</option>";
        }
        echo '</select>';  
      }
      // Get the model after user searched make.
      if(isset($_GET['getmodel'])  AND  isset($_GET['year']) AND isset($_GET['make'])){   
        $yr = $_GET['year'];
        $mk = $_GET['make'];
        $mo = $_GET['model]; 
        $res = mysql_query("SELECT model FROM Catalog WHERE year=$yr GROUP BY model ORDER BY model")
           or die("Invalid query: " . mysql_query());     
        echo 'Select Model:&nbsp;&nbsp;';
        echo '<select id="model" name="model" style="width: 170" onchange="getModel(this)">';
        echo '<option value="">Select</option>';
        while ($row = mysql_fetch_assoc($res)) {
           $mo = $row['model']; 
           echo "<option value=$mo>$mo</option>";
        }
        echo '</select>';
      } 
      // Get the description
      if(isset($_GET['getdesc'])  AND  isset($_GET['make'])  AND isset($_GET['year']) AND isset($_GET['model'])){   
        $mk = $_GET['make']; 
        $yr = $_GET['year'];
        $mo = $_GET['model];
        $res = mysql_query("SELECT exppartno FROM Catalog WHERE year=$yr AND make=$mk AND model=$mo")
           or die("Invalid query: " . mysql_query());
        echo "Make:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$mk<br />";
        
        $res = mysql_query("SELECT exppartno FROM Catalog WHERE year=$yr GROUP BY exppartno ORDER BY exppartno")
           or die("Invalid query: " . mysql_query()); 
           
        while ($row = mysql_fetch_assoc($res)) {
          $ds = $row['exppartno'];
          echo "<p><b>Part Number:</b>&nbsp;$ds&nbsp;<br></p>";
        }
      } 
      ?>

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #18
        What is the point of these 2 mysql queries? And which one is correct?
        [php] $res = mysql_query("SE LECT exppartno FROM Catalog WHERE year=$yr AND make=$mk AND model=$mo")
        or die("Invalid query: " . mysql_query());
        echo "Make:&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;$mk<br />";

        $res = mysql_query("SE LECT exppartno FROM Catalog WHERE year=$yr GROUP BY exppartno ORDER BY exppartno")
        or die("Invalid query: " . mysql_query()); [/php]
        Ronald :cool:

        Comment

        • Chrisjc
          Contributor
          • Nov 2006
          • 375

          #19
          Originally posted by ronverdonk
          What is the point of these 2 mysql queries? And which one is correct?
          [php] $res = mysql_query("SE LECT exppartno FROM Catalog WHERE year=$yr AND make=$mk AND model=$mo")
          or die("Invalid query: " . mysql_query());
          echo "Make:&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;$mk<br />";

          $res = mysql_query("SE LECT exppartno FROM Catalog WHERE year=$yr GROUP BY exppartno ORDER BY exppartno")
          or die("Invalid query: " . mysql_query()); [/php]
          Ronald :cool:
          well the first one Is for how it searches it.. then the 2nd one if for how it is put all nicely..... how else could I do it???? I would quess maybe i could get rid of the 1st one?????

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #20
            I have looked at the code you showed and I have corrected a few errors.
            Here is the corrected code.
            BUT TAKE CARE: the values taken from the database are stored in both the value and the description part of the <option> statements. That means that, if one of these variables contains balnks in-between (say a value 'Ford Galaxy V12'), that the value picked up by JavaScript will include the value up until the next blank!!! So in the former sample, it will pick up only the value 'Ford'. Take that into account. So for your testing of the drop-down boxes, I advise to have non-blank characters.

            Also, you'll have to change the db functions by your own.
            [php]
            Program cars.php:

            <html><head><ti tle>Test drop down cars</title>
            <style>label {width:100px;}</style>
            <script type="text/javascript" src="ajax.js"></script>
            <script type="text/javascript">
            var ajax = new sack();
            var selYear;
            var selMake;
            var selModel;
            /* =============== =============== =============== =============== =============== ====*/
            /* GET the MAKE drop down list after user has selected year */
            /* =============== =============== =============== =============== =============== ====*/
            function getMake(sel) {
            selYear = sel.options[sel.selectedInd ex].value;
            if(selYear.leng th>0){
            ajax.requestFil e = 'getCarInfo.php ?getmake=1&year ='+selYear; // Specifying what to get
            ajax.onCompleti on = createDropdownM ake; // Specify function that will be executed after file has been found
            ajax.runAJAX(); // Execute AJAX function
            }
            }
            // =============== =============== =============== =============== =============== ====
            // DISPLAY the MAKE drop down list
            // =============== =============== =============== =============== =============== ====
            function createDropdownM ake() {
            document.getEle mentById("divms g1").innerHTM L = ajax.response;
            }
            // =============== =============== =============== =============== =============== ====
            // GET the MODEL drop down list data after user has selected year and make
            // =============== =============== =============== =============== =============== ====
            function getModel(sel) {
            selMake = sel.options[sel.selectedInd ex].value;
            if(selMake.leng th>0){
            ajax.requestFil e = 'getCarInfo.php ?getmodel=1&mak e='+selMake+'&y ear='+selYear; // Specifying what to get
            ajax.onCompleti on = createDropdownM odel; // Specify function that will be executed after file has been found
            ajax.runAJAX(); // Execute AJAX function
            }
            }
            // =============== =============== =============== =============== =============== ====
            // DISPLAY the MODEL drop down list
            // =============== =============== =============== =============== =============== ====
            function createDropdownM odel() {
            document.getEle mentById("divms g2").innerHTM L = ajax.response;
            }
            // =============== =============== =============== =============== =============== ====
            // GET the EXPPARTNO after user has selected year, make and model
            // =============== =============== =============== =============== =============== ====
            function getPart(sel) {
            selModel = sel.options[sel.selectedInd ex].value;
            if(selModel.len gth>0){
            ajax.requestFil e = 'getCarInfo.php ?getpart=1&make ='+selMake+'&ye ar='+selYear+'& model='+selMode l; // Specifying what to get
            ajax.onCompleti on = createPart; // Specify function that will be executed after file has been found
            ajax.runAJAX(); // Execute AJAX function
            }
            }
            // =============== =============== =============== =============== =============== ====
            // DISPLAY the EXPPARTNO
            // =============== =============== =============== =============== =============== ====
            function createPart() {
            document.getEle mentById("divms g3").innerHTM L = ajax.response;
            }

            </script>
            </head>
            <body>
            <?php
            // =============== =============== =============== ==========
            // Populate the YEARS selection list from the database
            // =============== =============== =============== ==========
            echo '<u><b>aFe Vehicle Search Browser v3</b></u>';
            echo '<form action="" method="post">
            <label>Select year:</label>
            <select id="years" name="years" style="width: 170" onchange="getMa ke(this)">
            <option value="">Select </option>';
            // =============== =============== =============== ==========
            // Connection to the Database
            // =============== =============== =============== ==========
            $conn = mysql_connect(" localhost","xxx xx","yyyy")
            or die("Could not connect to the database server: ".mysql_error() );
            mysql_select_db ("zzzz",$con n)
            or die("Could not select the database: " . mysql_error());
            // =============== =============== =============== ==========
            // SELECT year to make drop down list
            // =============== =============== =============== ==========
            $res = mysql_query("SE LECT year FROM catalog GROUP BY year ORDER BY year DESC")
            or die("Invalid query: " . mysql_query());
            while ($row = mysql_fetch_ass oc($res)) {
            $yr = $row['year'];
            echo "<option value=$yr>$yr</option>";
            }
            echo '</select>';
            ?>
            <DIV ID="divmsg1" STYLE="top:3px; right:0px;posit ion:relative;he ight:30px;overf low:hidden;"></DIV>
            <DIV ID="divmsg2" STYLE="top:0px; right:0px;posit ion:relative;he ight:30px;overf low:hidden;"></DIV>
            <DIV ID="divmsg3" STYLE="top:0px; right:0px;posit ion:relative;he ight:30px;overf low:hidden;"></DIV>
            </form>
            </body></html>

            Program getCarInfo: (mind the use of upper case!!)
            <?php
            // =============== =============== =============== =============== =============== ==
            // Connection to the Database
            // =============== =============== =============== =============== =============== ==
            $conn = mysql_connect(" localhost","xxx x","yyyy")
            or die("Could not connect to the database server: ".mysql_error() );
            mysql_select_db ("zzzz",$con n)
            or die("Could not select the database: " . mysql_error());
            // =============== =============== =============== =============== =============== ==
            // Get the make after user selected year and create MAKE-dropdown list
            // =============== =============== =============== =============== =============== ==
            if(isset($_GET['getmake']) AND isset($_GET['year'])){
            $yr = $_GET['year'];
            $res = mysql_query("SE LECT make FROM catalog WHERE year=$yr GROUP BY make ORDER BY make")
            or die("Invalid query: " . mysql_query());
            echo '<label>Select make:</label>';
            echo '<select id="make" name="make" style="width: 170" onchange="getMo del(this)">';
            echo '<option value="">Select </option>';
            while ($row = mysql_fetch_ass oc($res)) {
            $mk = $row['make'];
            echo "<option value=$mk>$mk</option>";
            }
            echo '</select>';
            }
            // =============== =============== =============== =============== =============== ===
            // Get the model after user selected year and make and create MODEL-dropdown list
            // =============== =============== =============== =============== =============== ===
            if(isset($_GET['getmodel']) AND isset($_GET['make']) AND isset($_GET['year'])){
            $mk = $_GET['make'];
            $yr = $_GET['year'];
            $res = mysql_query("SE LECT model FROM Catalog WHERE year=$yr AND make='$mk'")
            or die("Invalid query: " . mysql_query());
            echo '<label>Select model:</label>';
            echo '<select id="model" name="model" style="width: 170" onchange="getPa rt(this)">';
            echo '<option value="">Select </option>';
            while ($row = mysql_fetch_ass oc($res)) {
            $mo = $row['model'];
            echo "<option value=$mo>$mo</option>";
            }
            echo '</select>';
            }
            // =============== =============== =============== =============== =============== ===
            // Get the exppartno after user selected year, make, model and display exppartno
            // =============== =============== =============== =============== =============== ===
            if(isset($_GET['getpart']) AND isset($_GET['make']) AND isset($_GET['year']) AND isset($_GET['model']) ){
            $mk = $_GET['make'];
            $yr = $_GET['year'];
            $mo = $_GET['model'];
            $res = mysql_query("SE LECT exppartno FROM Catalog WHERE year=$yr AND make='$mk' AND model='$mo'")
            or die("Invalid query: " . mysql_query());
            echo '<label>Part number:</label>';
            while ($row = mysql_fetch_ass oc($res)) {
            $pn = $row['exppartno'];
            echo "$pn<br />";
            }
            }
            ?>
            [/php]

            Ronald :cool:

            Comment

            • Chrisjc
              Contributor
              • Nov 2006
              • 375

              #21
              :( I loaded it all up and I get my year drop down.. but once I try to select something I get an error on page.... still something going on.. I had to fix a few things I found ( I.E.) FROM Catalog (not FROM catalog) my Database is in CAPS :) or at lest the name is for it... (Catalog)

              I am trying to look and see if I see anything.. I sent you the code I changed in your e-mail please have a look thanks for all your help

              Chris

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #22
                1. the caps on the table name is not important.
                2. do you have the ajax.js in your directory where index.php is located??

                I loaded it up here and it runs fine.

                Ronald :cool:

                Comment

                • Chrisjc
                  Contributor
                  • Nov 2006
                  • 375

                  #23
                  Originally posted by ronverdonk
                  1. the caps on the table name is not important.
                  2. do you have the ajax.js in your directory where index.php is located??

                  I loaded it up here and it runs fine.

                  Ronald :cool:
                  I fixed it.. I though I had saved it right.. it was the point of the ajax... sorry that was my fault... I sent you a message on a new issue... well its in this thread already we just never got to talking about it...

                  Comment

                  • Chrisjc
                    Contributor
                    • Nov 2006
                    • 375

                    #24
                    I have looked at the code you showed and I have corrected a few errors.
                    Here is the corrected code.
                    BUT TAKE CARE: the values taken from the database are stored in both the value and the description part of the <option> statements. That means that, if one of these variables contains balnks in-between (say a value 'Ford Galaxy V12'), that the value picked up by JavaScript will include the value up until the next blank!!! So in the former sample, it will pick up only the value 'Ford'. Take that into account. So for your testing of the drop-down boxes, I advise to have non-blank characters.

                    Also, you'll have to change the db functions by your own.
                    I don't fully understand why it is doing that.... It worked fine the other way.. now that we added model it is doing that??? In other words you saying I can't have spaces in my Database????? but I have to how could I fix this issue...??

                    Comment

                    • ronverdonk
                      Recognized Expert Specialist
                      • Jul 2006
                      • 4259

                      #25
                      Thai is because in the test table we never had values with embedded blanks. That is how I found out. There must be ways to get out of this (one is using encoding). I'll try to find out via the JavaScript forum.

                      Ronald :cool:

                      Comment

                      • Chrisjc
                        Contributor
                        • Nov 2006
                        • 375

                        #26
                        Originally posted by ronverdonk
                        Thai is because in the test table we never had values with embedded blanks. That is how I found out. There must be ways to get out of this (one is using encoding). I'll try to find out via the JavaScript forum.

                        Ronald :cool:
                        Okay well what are you searching for so I can help find an answer too.... I dont know what to look for....

                        Maybe while we look for that in the mean while you can help me with the issue of the ALL thing.. I still can't get it to work...

                        Check your inbox for what I changed...

                        Comment

                        • Chrisjc
                          Contributor
                          • Nov 2006
                          • 375

                          #27
                          So besides that I went ahead and added another Dropdown... I got it to work fine how ever... it will not give me a PART number.....

                          http://triplesource.ne t/db/

                          By the time you see this I might have more dropdowns... added in... soooo I will send you my code in your e-mail... when I am finish I think you logged for the night... Thanks for all your help

                          Chris

                          Comment

                          • Chrisjc
                            Contributor
                            • Nov 2006
                            • 375

                            #28
                            [PHP]
                            <html><head><ti tle>aFe Vehicle Search Browser v3</title>
                            <style>label {width:100px;}</style>
                            <script type="text/javascript" src="ajax/ajax.js"></script>
                            <script type="text/javascript">
                            var ajax = new sack();
                            var selGD;
                            var selYear;
                            var selMake;
                            var selModel;
                            var selLiter;
                            // =============== =============
                            // GET the YEAR drop down list after user has selected GAS / DIESEL
                            // =============== ========
                            function getYear(sel) {
                            selGD = sel.options[sel.selectedInd ex].value;
                            if(selGD.length >0){
                            ajax.requestFil e = 'getCarInfo.php ?getyear=1&GD=' +selGD; // Specifying what to get
                            ajax.onCompleti on = createDropdownY ear; // Specify function that will be executed after file has been found
                            ajax.runAJAX(); // Execute AJAX function
                            }
                            }
                            // =============== =============== ====
                            // DISPLAY the YEAR drop down list
                            // =============== =============== ====
                            function createDropdownY ear() {
                            document.getEle mentById("divms g1").innerHTM L = ajax.response;
                            }
                            // =============== =============== =========
                            // GET the MAKE drop down list after user has selected year
                            // =============== =============== =========
                            function getMake(sel) {
                            selYear = sel.options[sel.selectedInd ex].value;
                            if(selYear.leng th>0){
                            ajax.requestFil e = 'getCarInfo.php ?getmake=1&year ='+selYear+'&GD ='+selGD; // Specifying what to get
                            ajax.onCompleti on = createDropdownM ake; // Specify function that will be executed after file has been found
                            ajax.runAJAX(); // Execute AJAX function
                            }
                            }
                            // =============== =============== =========
                            // DISPLAY the MAKE drop down list
                            // =============== =============== =========
                            function createDropdownM ake() {
                            document.getEle mentById("divms g2").innerHTM L = ajax.response;
                            }
                            // =============== =============== ====
                            // GET the MODEL drop down list data after user has selected year and make
                            // =============== =============== ====
                            function getModel(sel) {
                            selMake = sel.options[sel.selectedInd ex].value;
                            if(selMake.leng th>0){
                            ajax.requestFil e = 'getCarInfo.php ?getmodel=1&mak e='+selMake+'&y ear='+selYear+' &GD='+selGD; ; // Specifying what to get
                            ajax.onCompleti on = createDropdownM odel; // Specify function that will be executed after file has been found
                            ajax.runAJAX(); // Execute AJAX function
                            }
                            }
                            // =============== ==============
                            // DISPLAY the MODEL drop down list
                            // =============== ==============
                            function createDropdownM odel() {
                            document.getEle mentById("divms g3").innerHTM L = ajax.response;
                            }
                            // =============== ============
                            // GET the LITER after user has selected year, make and model
                            // =============== ============
                            function getLiter(sel) {
                            selModel = sel.options[sel.selectedInd ex].value;
                            if(selModel.len gth>0){
                            ajax.requestFil e = 'getCarInfo.php ?getliter=1&mak e='+selMake+'&y ear='+selYear+' &model='+selMod el+'&GD='+selGD ; // Specifying what to get
                            ajax.onCompleti on = createDropdownL iter; // Specify function that will be executed after file has been found
                            ajax.runAJAX(); // Execute AJAX function
                            }
                            }
                            // =============== =========
                            // DISPLAY the EXPPARTNO
                            // =============== =========
                            function createDropdownL iter() {
                            document.getEle mentById("divms g4").innerHTM L = ajax.response;
                            }
                            // =============== =============== =
                            // GET the EXPPARTNO after user has selected year, make, model and liter
                            // =============== =============== =
                            function getPart(sel) {
                            selLiter = sel.options[sel.selectedInd ex].value;
                            if(selLiter.len gth>0){
                            ajax.requestFil e = 'getCarInfo.php ?getpart=1&lite r='+selLiter+'& make='+selMake+ '&year='+selYea r+'&model='+sel Model+'&GD='+se lGD; // Specifying what to get
                            ajax.onCompleti on = createPart; // Specify function that will be executed after file has been found
                            ajax.runAJAX(); // Execute AJAX function
                            }
                            }
                            // =============== =============
                            // DISPLAY the EXPPARTNO
                            // =============== =============
                            function createPart() {
                            document.getEle mentById("divms g5").innerHTM L = ajax.response;
                            }

                            </script>
                            </head>
                            <body>
                            <?php
                            // =============== ============
                            // Populate the YEARS selection list from the database
                            // =============== ============
                            echo '<u><b>aFe Vehicle Search Browser v3</b></u>';
                            echo '<form action="" method="post">
                            <label>Select Fuel:</label>
                            <select id="fuel" name="fuel" style="width: 170" onchange="getYe ar(this)">
                            <option value="">Select </option>';
                            // =============== ============
                            // Connection to the Database
                            // =============== ============
                            include ('db functions/db_connect.php' );
                            // =============== ==============
                            // SELECT year to make drop down list
                            // =============== ==============
                            $res = mysql_query("SE LECT fuel FROM Catalog GROUP BY fuel ORDER BY fuel")
                            or die("Invalid query: " . mysql_query());
                            while ($row = mysql_fetch_ass oc($res)) {
                            $gd = $row['fuel'];
                            echo "<option value=$gd>$gd</option>";
                            }
                            echo '</select>';
                            ?>
                            <DIV ID="divmsg1" STYLE="top:3px; right:0px;posit ion:relative;he ight:30px;overf low:hidden;"></DIV>
                            <DIV ID="divmsg2" STYLE="top:0px; right:0px;posit ion:relative;he ight:30px;overf low:hidden;"></DIV>
                            <DIV ID="divmsg3" STYLE="top:0px; right:0px;posit ion:relative;he ight:30px;overf low:hidden;"></DIV>
                            <DIV ID="divmsg4" STYLE="top:0px; right:0px;posit ion:relative;he ight:30px;overf low:hidden;"></DIV>
                            <DIV ID="divmsg5" STYLE="top:0px; right:0px;posit ion:relative;he ight:30px;overf low:hidden;"></DIV>
                            </form>
                            </body></html>
                            [/PHP]

                            The next part of the code........... ..

                            getCarInfo.php
                            [PHP]<?php
                            // =============== =============== ===
                            // Connection to the Database
                            // =============== =============== ===
                            include ('db functions/db_connect.php' );
                            // =============== =============== ==
                            // Get the year after user selected Gas / Diesel and create YEAR-dropdown list
                            // =============== =============== ==
                            if(isset($_GET['getyear']) AND isset($_GET['fuel'])){
                            $gd = $_GET['fuel'];
                            $res = mysql_query("SE LECT year FROM Catalog WHERE fuel='$gd' GROUP BY year ORDER BY year DESC")
                            or die("Invalid query: " . mysql_query());
                            echo '<label>Select year:</label>';
                            echo '<select id="year" name="year" style="width: 170" onchange="getMa ke(this)">';
                            echo '<option value="">Select </option>';
                            while ($row = mysql_fetch_ass oc($res)) {
                            $yr = $row['year'];
                            echo "<option value=$yr>$yr</option>";
                            }
                            echo '</select>';
                            }

                            // =============== =============== ====
                            // Get the make after user selected GAS / DIESEL, year and create MAKE-dropdown list
                            // =============== =============== ====
                            if(isset($_GET['getmake']) AND isset($_GET['fuel']) AND isset($_GET['year'])){
                            $yr = $_GET['year'];
                            $res = mysql_query("SE LECT make FROM Catalog WHERE fuel='$gd' year='$yr' GROUP BY make ORDER BY make")
                            or die("Invalid query: " . mysql_query());
                            echo '<label>Select make:</label>';
                            echo '<select id="make" name="make" style="width: 170" onchange="getMo del(this)">';
                            echo '<option value="">Select </option>';
                            while ($row = mysql_fetch_ass oc($res)) {
                            $mk = $row['make'];
                            echo "<option value=$mk>$mk</option>";
                            }
                            echo '</select>';
                            }
                            // =============== =============== ======
                            // Get the model after user selected GAS / DIESEL, year and make and create MODEL-dropdown list
                            // =============== =============== ======
                            if(isset($_GET['getmodel']) AND isset($_GET['fuel']) AND isset($_GET['make']) AND isset($_GET['year'])){
                            $gd = $_GET['fuel'];
                            $mk = $_GET['make'];
                            $yr = $_GET['year'];
                            $res = mysql_query("SE LECT model FROM Catalog WHERE fuel='$gd' year='$yr' AND make='$mk' GROUP BY model ORDER BY model")
                            or die("Invalid query: " . mysql_query());
                            echo '<label>Select model:</label>';
                            echo '<select id="model" name="model" style="width: 170" onchange="getLi ter(this)">';
                            echo '<option value="">Select </option>';
                            while ($row = mysql_fetch_ass oc($res)) {
                            $mo = $row['model'];
                            echo "<option value=$mo>$mo</option>";
                            }
                            echo '</select>';
                            }
                            // =============== ============
                            // Get the liter after user selected GAS / DIESEL, year, make, model, and create LITER-dropdown list
                            // =============== ============
                            if(isset($_GET['getliter']) AND isset($_GET['fuel']) AND isset($_GET['make']) AND isset($_GET['year']) AND isset($_GET['model'])){
                            $gd = $_GET['fuel'];
                            $mk = $_GET['make'];
                            $yr = $_GET['year'];
                            $mo = $_GET['model'];
                            $res = mysql_query("SE LECT liter FROM Catalog WHERE fuel='$gd' year='$yr' AND make='$mk' AND model='$mo' GROUP BY liter ORDER BY liter")
                            or die("Invalid query: " . mysql_query());
                            echo '<label>Select liter:</label>';
                            echo '<select id="liter" name="liter" style="width: 170" onchange="getPa rt(this)">';
                            echo '<option value="">Select </option>';
                            while ($row = mysql_fetch_ass oc($res)) {
                            $lt = $row['liter'];
                            echo "<option value=$lt>$lt</option>";
                            }
                            echo '</select>';
                            }
                            // =============== =============== ==
                            // Get the exppartno after user selected year, make, model, liter, and display exppartno
                            // =============== =============== ==
                            if(isset($_GET['getpart']) AND isset($_GET['fuel']) AND isset($_GET['make']) AND isset($_GET['year']) AND isset($_GET['model']) AND isset($_GET['liter'])){
                            $gd = $_GET['fuel'];
                            $mk = $_GET['make'];
                            $yr = $_GET['year'];
                            $mo = $_GET['model'];
                            $res = mysql_query("SE LECT exppartno FROM Catalog WHERE fuel='$gd' year='$yr' AND make='$mk' AND model='$mo' AND liter='$lt' GROUP BY exppartno ORDER BY exppartno")
                            or die("Invalid query: " . mysql_query());
                            echo '<label><b>Par t number:</b></label>';
                            while ($row = mysql_fetch_ass oc($res)) {
                            $pn = $row['exppartno'];
                            echo "<p>&nbsp;$pn&n bsp;<br></p>"; }
                            }
                            ?>
                            [/PHP]


                            ( www.triplesource.net/db/ )

                            Comment

                            • Chrisjc
                              Contributor
                              • Nov 2006
                              • 375

                              #29
                              Incase your wondering to by the way... I have to have the drop downs like this

                              GAS/DIESEL: which in the Database = ( Fuel )
                              YEAR
                              MAKE
                              MODEL
                              Engine Type: In the Database = ( engtype )
                              LITER

                              Now I am supposed to list it like this exactly…

                              GAS/DIESEL
                              MAKE
                              MODEL
                              YEAR
                              EGINE TYPE
                              LITER

                              How ever… I do not agree with that layout… there for lets stick with what I started it as… If I have to I will change it later… should be to hard… just a switch around… of code…..

                              Thanks for all your help

                              Chris

                              Comment

                              • ronverdonk
                                Recognized Expert Specialist
                                • Jul 2006
                                • 4259

                                #30
                                The blank issue is entirely my fault. (I should not go on until 1.30 AM, makes me forgetful).
                                I forgot to enclose the value within quotes. You should change all statements like this one in getCarInfo and enclose the value in the option statement within single quotes.
                                [php]echo "<option value='$lt'>$lt </option>"; [/php]

                                Ronald :cool:

                                Comment

                                Working...