title: how to retrieve data from database based on the value of two drop down list using ajax?
body: <p>i have implemented the <a href="http://www.w3schools.com/php/php_ajax_database.asp" rel="nofollow">Example</a>. Here i am retrieving data using only one drop down list. Its working fine. But if I want to do the same for two drop down list that is values from database have to be retrieved based on the value of two drop down list.
  I am trying as follows:
  Ajax script-</p>
  
  <pre><code>&lt;script&gt; // AJAX Implementation
  function showCourses() {
      str = document.getElementById("branch").value;
      str1 = document.getElementById("sem").value;
      if (str == "" || str1 == "") {
          document.getElementById("txtHint").innerHTML = "";
          return;
      }
      if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp = new XMLHttpRequest();
      } else { // code for IE6, IE5
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange = function () {
          if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
              document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
          }
      }
      xmlhttp.open("GET", "listCourseByAjax.php?p=" + str + "&amp;q=" + str1, true);
      xmlhttp.send();
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>drop down lists-</p>
  
  <pre><code>&lt;select name="branch" onchange="showCourses(this.value)"&gt;
          &lt;option id="branch" value="0" selected&gt;Select one&lt;/option&gt;
              &lt;option id="branch" value="ISE"&gt;1/option&gt;
              &lt;option id="branch" value="CSE"&gt;2&lt;/option&gt;
              &lt;option id="branch" value="ME"&gt;3&lt;/option&gt;
  &lt;/select&gt;
  &lt;select name="sem" onchange="showCourses(this.value)"&gt;
      &lt;option id="sem" value="0" selected&gt;select one&lt;/option&gt;
      &lt;option id="sem" value="I-P"&gt;I-P&lt;/option&gt;
      &lt;option id="sem" value="I-C"&gt;I-C&lt;/option&gt;
      &lt;option id="sem" value="II-P"&gt;II-P&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>php file-</p>
  
  <pre><code>$p = $_GET['p'];
  $q = $_GET['q'];
  $sql="SELECT * FROM course_details WHERE sem='" . $q . "' AND branch='" . $p . "'";
  $result = mysql_query($sql);
  
  echo "&lt;table border='1'&gt;
  &lt;tr&gt;
      &lt;th&gt;Course Code&lt;/th&gt;
      &lt;th&gt;Course Name&lt;/th&gt;
      &lt;th&gt;Course Instructor&lt;/th&gt;
      &lt;th&gt;Credit&lt;/th&gt;
  &lt;/tr&gt;";
  </code></pre>
  
  <p>Please help me how to do it.</p>