title: PHP Mysql simplification
body: <p>Can anyone help me simplify this?  I have a page for viewing a bunch of data from a table, the page is supposed to accept different values via GET calls.  I'd just like to slim it down a bit.  Again, the code works, it's just spaghetti to me. </p>
  
  <pre><code>if(!$_REQUEST['foo']){
      $bar = $_REQUEST['bar'];
      if($bar=='all'||!$bar){ $stmt = "SELECT * FROM table
          WHERE qty &gt; 0  and
               somedate &gt;= \"{$start}\"  and
               somedate &lt;= \"{$end}\"
          ORDER BY id desc
          ";}
      else{
      $stmt = "SELECT * FROM table
          WHERE qty &gt; 0  and
               somedate &gt;= \"{$start}\"  and
               somedate &lt;= \"{$end}\"  and
               bar = '$bar'
          ORDER BY id desc
          ";}
  }
  else{
       switch($_REQUEST['foo']){
         case 'all':
          $stmt = "SELECT * FROM table
            WHERE qty &gt; 0  and
            somedate &gt;= \"{$start}\"  and
            somedate &lt;= \"{$end}\"
            ORDER BY id desc";
          break;
       case 'open':
        $stmt = "SELECT * FROM table
            WHERE qty &gt; 0  and
            closd = 0 and
            somedate &gt;= \"{$start}\"  and
            somedate &lt;= \"{$end}\"
            ORDER BY id desc";
        break;
       case 'closed':
        $stmt = "SELECT * FROM table
            WHERE qty &gt; 0  and
            closd = 1 and
            somedate &gt;= \"{$start}\"  and
            somedate &lt;= \"{$end}\"
            ORDER BY id desc";
        break;
  }}
  </code></pre>