title: PHP MySQL statement with multiple variable components
body: <p>I am producing an API that takes in certain parameters, carries out an algorithm and returns the results. As part of this process I have several different clauses that can go into the SQL statement based on what is sent to the API. This has produced many sections of this format:</p>
  
  <pre><code>if(isset($_GET['val'])) {
      $sqljoin = " INNER JOIN b ON b.1=a.1 "
      $sqlwhere = " WHERE b.2 = " . $_GET['val'];
  }
  $sql = "SELECT * FROM a " . $sqljoin . $sqlwhere;
  </code></pre>
  
  <p>Which was fine initially, but now I have approximately 6 different clauses going into it, both with a JOIN and a WHERE clause. Is there a better way of structuring this?</p>