title: Get instant results from dropdownlist with jquery/php
body: <p>I want my dropdown list to automatically collect the right results from a database without refreshing the page.</p>
  
  <p>I wrote code with jQuery but somehow it calls my front-end twice instead of calling the results of a select statement.</p>
  
  <p>Here's my javasacript code: </p>
  
  <pre><code>$(document).ready(function() {
      function ajaxLoaded(response) {
          $('#performanceResults').html(response);
      }
      function doRequest() {
          $.ajax({
              url: "results.php",
              type: 'POST',
              success: ajaxLoaded
          });
      }
      $('#performance').change(doRequest);
  });
  </code></pre>
  
  <p>This is the method that contains my form:</p>
  
  <pre><code>public function SelectPerformanceIndicator() {
          $this-&gt;getResults ();
  
          $str = '&lt;form &gt;';
          $str .= 'Select your performance indicator&lt;br&gt;';
          $str .= '&lt;select id = "performance"&gt;';
          $str .= '&lt;option value = ""&gt;Select Performance Indicator&lt;/option&gt;';
          $str .= '&lt;option value = "1"&gt;Cost per auction  &lt;/option&gt;';
          $str .= '&lt;option value = "2"&gt;Fillrate &lt;/option&gt;';
          $str .= '&lt;/select&gt;';
          $str .= '&lt;/form&gt;';
          $str .= '&lt;br&gt;';
          $str .= '&lt;div id="performanceResults"&gt;&lt;/div&gt;';
  
          return $str;
      }
  </code></pre>
  
  <p>And this is the method that should create a table depending on which value I select in my front-end.</p>
  
  <pre><code>public function getResults() {
          $intCase = intval ( $_POST ['q'] );
  
          if ($intCase == 1 or $intCase == 2) {
              if ($intCase == 1) {
                  $strSql = 'select bidder_id, won, lost, fillrate, costs, cost_auction from result_bidder where tagload = ( select max(tagload) from result_bidder) order by cost_auction asc limit 1';
              }
              if ($intCase == 2) {
                  $strSql = 'select bidder_id, won, lost, fillrate, costs, cost_auction from result_bidder where tagload = ( select max( tagload ) from result_bidder ) order by fillrate asc limit 1';
              }
              if (! isset ( $_POST ['jquery'] )) {
                  $arrBestPerformer = $objDatabase-&gt;queryresult ( $strSql );
                  echo "&lt;table border='1'&gt;
              &lt;tr&gt;
              &lt;th&gt;bidder_id&lt;/th&gt;
              &lt;th&gt;won&lt;/th&gt;
              &lt;th&gt;lost&lt;/th&gt;
              &lt;th&gt;fillrate&lt;/th&gt;
              &lt;th&gt;costs&lt;/th&gt;
              &lt;th&gt;cost_auction&lt;/th&gt;
              &lt;/tr&gt;";
  
                  while ( $row = mysqli_fetch_array ( $arrBestPerformer ) ) {
                      echo "&lt;tr&gt;";
                      echo "&lt;td&gt;" . $row ['bidder_id'] . "&lt;/td&gt;";
                      echo "&lt;td&gt;" . $row ['won'] . "&lt;/td&gt;";
                      echo "&lt;td&gt;" . $row ['lost'] . "&lt;/td&gt;";
                      echo "&lt;td&gt;" . $row ['fillrate'] . "&lt;/td&gt;";
                      echo "&lt;td&gt;" . $row ['costs'] . "&lt;/td&gt;";
                      echo "&lt;td&gt;" . $row ['cost_auction'] . "&lt;/td&gt;";
                      echo "&lt;/tr&gt;";
                  }
                  echo "&lt;/table&gt;";
              }
          }
      }
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p>Edit  to clarify current results:</p>
  
  <p>Front-end without selecting a value in the drop-down:</p>
  
  <pre><code>Image
  
  Dropdownlist
  
  Results of a simulation
  </code></pre>
  
  <p>Front-end with selecting a value in the drop-down:</p>
  
  <pre><code>Image
  
  Dropdownlist
  
  *Image
  
  *Dropdownlist
  
  *Results of a simulation
  </code></pre>
  
  <p><strong>This is where jquery calls the front-end twice</strong></p>