title: Define MYSQL query according to values sent from another page
body: <p>I am trying to set a MYSQL query based on the presence (or absence) of values sent across from a parent page via the URL. The variables are the following:</p>
  
  <pre><code>        $startdate = $_GET["selectstartdate"];
          $enddate = $_GET["selectenddate"];
          $ensemble = $_GET["selectensemble"];
          $venue = $_GET["selectvenue"];
          $city = $_GET["selectcity"];
  </code></pre>
  
  <p>The first two will ALWAYS be non-NULL, but the remaining three have a default value of NULL, which may or may not be redefined on the parent page. So, what I need to do is to restructure my SQL query, according to which of these variables I receive.</p>
  
  <p>IF only the first two variables are sent (and all others are NULL), then the following query is correct:</p>
  
  <pre><code>        $sql = "SELECT Concert.date, Ensemble.long_name, Concert.title, ensemble_web, Concert.info, Concert.repertoire, Venue.name, venue_web, Venue.address, Venue.city, Venue.map 
                  FROM Concert, Ensemble, Venue
                  WHERE Concert.ensemble_id = Ensemble.id AND Concert.venue_id = Venue.id
                  AND Concert.date BETWEEN '$startdate' AND '$enddate'";
  </code></pre>
  
  <p>However, if for example $ensemble is not NULL, then I would need an extra line added to my query:</p>
  
  <pre><code>                AND Ensemble.short_name='$ensemble';
  </code></pre>
  
  <p>Similarly, if $venue is not NULL, then I would need:</p>
  
  <pre><code>                AND Venue.name='$venue';
  </code></pre>
  
  <p>...and, of course, if $city is not NULL, then I would need:</p>
  
  <pre><code>                AND Venue.city='$city';
  </code></pre>
  
  <p>I am really what the best way to go about this is. Many thanks in advance for your help!</p>