title: Retrieve data from database based on selected Dropdown value using PHP and jquery AJAX
body: <p>I've UPDATED MY CODE BELOW AND IM GETTING &quot;500 (INTERNAL SERVER ERROR)&quot; on my php code.</p>
  <p>I'm fairly new to PHP and jQuery, Ajax, and I've been having a hard time trying to find a example on the internet that could lead me to solving my problem. anyone kind enough to explain to me how would I be able to display data from a database into a html TABLE based on the value of the selected dropdown, kind of a filter.</p>
  <p>I've already managed to load all the data from the database and it works, I've tried to look for an example online but couldn't find any.</p>
  <p>ADDING CODES:
  HTML CODE:
  
  </p>
  <pre><code>                &lt;select name=&quot;countryN&quot; id=&quot;countryCB&quot;&gt;
                  &lt;?php
                  while($rows = $resultSet-&gt;fetch_assoc())
                  {
                      $country = $rows['Country'];
                      echo &quot;&lt;option value='Test'&gt;$country&lt;/option&gt;&quot;;
                  }
                  ?&gt;
                  &lt;/select&gt;
  
                  &lt;input type=&quot;button&quot; class=&quot;srchbtn&quot; value=&quot;Seach&quot;&gt;
              
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;item-container&quot;&gt;
              &lt;div id=&quot;items&quot;&gt;
                  &lt;table id=&quot;brtable&quot;&gt;
                      &lt;thead&gt;
                          &lt;tr class=&quot;tblrow&quot; id=&quot;headers&quot;&gt;
                              &lt;th&gt;BR-Name&lt;/th&gt;
                              &lt;th&gt;Country&lt;/th&gt;
                              &lt;th&gt;Data Stream&lt;/th&gt;
                              &lt;th&gt;Region&lt;/th&gt;
                              &lt;th&gt;Actions to be taken&lt;/th&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;
                      &lt;tbody id=&quot;tableresult&quot;&gt;
  
                      &lt;/tbody&gt;
                  &lt;/table&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  <p>PHP CODE:</p>
  <pre><code>&lt;?php   
  $connect = mysqli_connect('127.0.0.1', 'root', '', 'testdb'); 
  $countryN = $_POST['Country'];
  $brfilterresult = (&quot;SELECT Business_Rule_Name, Country, Data_Stream, Region,         
  ActionNeeded FROM businessrulestbl WHERE Country='&quot;.$countryN.&quot;'&quot;);
  
  
  $result = $connect-&gt;query($brfilterresult);
  if ($result-&gt;num_rows &gt; 0) {
  while ($row = $result-&gt;fetch_assoc()) {
      echo &quot;&lt;tr&gt;&lt;td&gt;&quot; . $row['Business_Rule_Name'] . &quot;&lt;/td&gt;&quot;;
      echo &quot;&lt;td&gt;&quot; . $row['Country'] . &quot;&lt;/td&gt;&quot;;
      echo &quot;&lt;td&gt;&quot; . $row['Data_Stream'] . &quot;&lt;/td&gt;&quot;;
      echo &quot;&lt;td&gt;&quot; . $row['Region'] . &quot;&lt;/td&gt;&quot;;
      echo &quot;&lt;td&gt;&quot; . $row['ActionNeeded'] . &quot;&lt;/td&gt;&lt;/tr&gt;&quot;;
  }
  }
  ?&gt; 
  </code></pre>
  <p>JS code:</p>
  <pre><code>$(document).ready(function(){
  $('#countryCB').change(function(){
      var countryName = $(this).val();
      $.ajax({
          url:&quot;../php/getbr.php&quot;,
          method: &quot;POST&quot;,
          data: {countryName:countryName},
          success: function(data){
              $('#tableresult').html(data);
          }
      });
  });
  });
  </code></pre>
  <p>I just want someone to explain to me how would I be able to achieve my goal in a detailed manner, explaining each part. a sample source code would be great.</p>