title: Use a Drop Down Menu to Query A Database and Return the Results Either On The Same Page Or Another Page
body: <p>I have a page with some PHP that looks like this:</p>
  
  <pre><code>&lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th class="wheniwant"&gt;Date&lt;/th&gt;
              &lt;th class="wheniwant"&gt;Income Amount&lt;/th&gt;
              &lt;th class="wheniwant"&gt;Expense Amount&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
  
      &lt;?php
      //DB CONNECTION
  
      $varDatePaid = ""; $varIncomePaid =""; $varExpensePaid = "";
  
      $sql = mysql_query( 
          "
              SELECT DATE_FORMAT(`date_paid`, '%Y-%m') `date_paid`,
              SUM(CASE WHEN `categoryType` = 'Income' THEN `amount_paid` END) `IncomeAmount`,
              SUM(CASE WHEN `categoryType` = 'Expense' THEN `amount_paid` END) `ExpenseAmount`
              FROM `accounting`
              GROUP BY DATE_FORMAT(`date_paid`, '%Y-%m')
          "
       );
  
  
      while($row = mysql_fetch_array($sql))
          {
              $varDatePaid = $row['date_paid'];
              $varIncomePaid = $row['IncomeAmount'];
              $varExpensePaid = $row['ExpenseAmount'];                        
      ?&gt;
  
  
      &lt;tr&gt;
          &lt;td&gt;&lt;?php echo $varDatePaid; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $varIncomePaid; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $varExpensePaid; ?&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
      &lt;?php   
  
          }
      ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>This returns a table like:</p>
  
  <p><img src="https://i.stack.imgur.com/0OqpM.png" alt="Screenshot"></p>
  
  <p>I want to then add something:</p>
  
  <pre><code>$sql_query = "SELECT id, DATE_FORMAT(`date_paid`, '%Y') AS year FROM accounting GROUP BY year ORDER BY year DESC";
  
  
  $result = mysql_query($sql_query) or die(mysql_error());
  while ($row = mysql_fetch_array($result)){
  echo '&lt;option value='. $row['year'] . '&gt;'. $row['year'] . '&lt;/option&gt;';
  </code></pre>
  
  <p>To create some sort of filter to limit the result to a particular year. How do I do this without leaving the page?</p>