jquery - Run query based on two dropdown and show table PHP -


i have 2 dropdowns, second dropdown getting populated first dropdown condition. now, want take both dropdowns' conditions , apply query , show results in table via html.

this code,

script code:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script> <script type="text/javascript"> $(document).ready(function() {     $('.country').on('change', function() {     // code add country information in url      location.href = location.href.split('?')[0]         + ['?country', $(this).val()].join('=');     });  });  </script> 

php code first dropdown:

<?php $countries = mysqli_query($mysqli,"select source nhws.masterkey group source;"); echo "<select class='country' name='country' style='width:200px'>";  echo "<option size =30 ></option>"; while($row = mysqli_fetch_array($countries)){             echo "<option value='".$row['source']."'>".$row['source']."</option>";  } echo "</select>"; if (isset($_get['country'])) {     $country = $_get['country'];     echo "<p></p>";     echo "$country selected data set";     echo "<p></p>"; } ?> 

php code second dropdown:

<?php if (isset($_get['country'])) {     echo "<h5>choose variable</h5>";     $variables = mysqli_query($mysqli,"select variable nhws.num_all_{$country} group variable;");     echo "<select class='variable' name='variable' style=width:200px>";      echo "<option size =30 ></option>";     while($row = mysqli_fetch_array($variables)) {                 echo "<option value='".$row['variable']."'>".$row['variable']."</option>";      }     echo "</select>"; } ?> 

now, last php code display results table:

<?php if (isset($_get['variable'])) {     $results = mysqli_query($mysqli,"select q1.variable, q1.numvalue, description, num_cases     (select variable, numvalue, count(variable) num_cases      nhws.num_all_{$country}      variable = '{$variable}'     group variable, numvalue) q1     inner join (select * nhws.luvalues source = '{$country}' , variable = '{$variable}')     t2 on q1.numvalue=t2.numvalue;");     echo "<h5>counts</h5>";     if ($results->num_rows > 0) {          echo "<table><tr><th>variable</th><th>numvalue</th><th>description</th><th>num cases</th></tr>";          // output data of each row          while($row = $results->fetch_assoc()) {                 echo "<tr><td>" . $row["variable"]. "</td><td>" . $row["numvalue"]. "</td><td>" . $row["description"]. "</td><td>" . $row["num_cases"]. "</td></tr>";          }          echo "</table>";     } else {echo "0 results";}  } ?> 

once selecting dropdown option nothing happens. query doesn't run. looks doesn't go through if (isset($_get['variable'])) statement.

how can make work?

thanks!

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script> <script type="text/javascript"> $(document).ready(function() {     $('.country').on('change', function() {     // code add country information in url      location.href = location.href.split('?')[0]         + ['?country', $(this).val()].join('=');     });      $('.variable').on('change', function() {     // code add country information in url      location.href = location.href.split('?')[0]         + ['?variable', $(this).val()].join('=');     });  });  </script> 

php code first dropdown:

<?php $countries = mysqli_query($mysqli,"select source nhws.masterkey group source;"); echo "<select class='country' name='country' style='width:200px'>";  echo "<option size =30 ></option>"; while($row = mysqli_fetch_array($countries)){             echo "<option value='".$row['source']."''>".$row['source']."</option>";  } echo "</select>"; if (isset($_get['country'])) {     $_session['country'] = $_get['country'];     echo "<p></p>";     echo $_session['country'].' selected data set';     echo "<p></p>"; } ?> 

php code second dropdown:

<?php if (isset($_get['country'])) {     echo "<h5>choose variable</h5>";     $variables = mysqli_query($mysqli,"select variable nhws.num_all_{$country} group variable;");     echo "<select class='variable' name='variable' style=width:200px>";      echo "<option size =30 ></option>";     while($row = mysqli_fetch_array($variables)) {                 echo "<option value='".$row['variable']."'>".$row['variable']."</option>";      }     echo "</select>"; } ?> 

now, last php code display results table:

<?php if (isset($_get['variable'])) {     $_session['variable'] = $_get['variable'];     $results = mysqli_query($mysqli,"select q1.variable, q1.numvalue, description, num_cases     (select variable, numvalue, count(variable) num_cases      nhws.num_all_{$country}      variable = '{$variable}'     group variable, numvalue) q1     inner join (select * nhws.luvalues source = '{$_session['country']}' , variable = '{$_session['variable']}')     t2 on q1.numvalue=t2.numvalue;");     echo "<h5>counts</h5>";     if ($results->num_rows > 0) {          echo "<table><tr><th>variable</th><th>numvalue</th><th>description</th><th>num cases</th></tr>";          // output data of each row          while($row = $results->fetch_assoc()) {                 echo "<tr><td>" . $row["variable"]. "</td><td>" . $row["numvalue"]. "</td><td>" . $row["description"]. "</td><td>" . $row["num_cases"]. "</td></tr>";          }          echo "</table>";     } else {echo "0 results";}  } ?> 

fyi...you don't need $(document).ready, on() method still attach put javascript code after selects exist on page.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -