title: PHP query db in switch statement
body: <p>I am using a switch statement on a $_GET variable to produce the result I want on my page.</p>
  
  <p>I am always questioning the best way to run queries in situations like this because I simply do not know the best practice or method. So I have some pseudo code below and I was wondering what the best method would be.</p>
  
  <p>This very well could be a situation where is just doesn't matter in terms of performance, but if it does I want to make sure I do it right.</p>
  
  <pre><code>if(isset($_GET['type'])){
     $var = $_GET['type'];
  
    //run the query now and select everything needed from the DB for either switch case. 
    //view implications that involve pulled data
     switch($var){
  
     case '1':
  
    //Or do I run the query here, getting only what I need for this situation
    //view implications that involve pulled data
     break;
  
     case '2':
  
     //again run the query here, getting only what I need for this situation
     //view implications that involve pulled data
  
     break;
  
  
     }
  
  }
  </code></pre>
  
  <p>Both cases share one or two similar pieces of data from the DB, but a majority of the content for each case is only needed in that situation.</p>
  
  <p>Bottom line trying to perform the best and keep the code as clean and efficient as possible.</p>
  
  <p>Thanks!</p>