title: PHP - sorting a list using a drop down menu
body: <p>I am stuck with this, I have been putting myself through a crash course in PHP all week making a fake amazon like site! I want to order my table using a drop down menu but cant work out how! I know the SQL thats the easy bit but the way I have tried to do it is follows:</p>
  
  <p>Set up variables for example</p>
  
  <pre><code>$query = "SELECT bookname, bookauthor, bookpub, bookisbn
                  FROM booktable
                  ORDER BY bookname ASC";
  
  $query2 = "SELECT bookname, bookauthor, bookpub, bookisbn
              FROM booktable
              ORDER BY bookauthor ASC";
  </code></pre>
  
  <p>Then I have my form=</p>
  
  <pre><code>&lt;form name="sort" action="products.php" method="post"&gt;
  &lt;select name="order"&gt;
     &lt;option value="choose"&gt;Make A Selection&lt;/option&gt;
     &lt;option value="title"&gt;Title&lt;/option&gt;
     &lt;option value="author"&gt;Author&lt;/option&gt;
     &lt;option value="publisher"&gt;Publisher&lt;/option&gt;
     &lt;option value="isbn"&gt;Book ISBN-10&lt;/option&gt;
  &lt;/select&gt;
  &lt;input type="submit" value=" - Sort - " /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Now for the bit I cant do,</p>
  
  <p>I set up the variable: </p>
  
  <pre><code>$sort = $_POST['order']; 
  </code></pre>
  
  <p>so that whatever the value of the dropdown menu is, will become assigned to the variable $sort..... (is that right?)</p>
  
  <p>then I want to say IF the value of $sort is the same as lets say 'author' than $query = $query2
  but I dont know how to say it without huge error courtesy of XAMPP!</p>
  
  <p>I hope this all makes sense and that my method to try and achieve it is close to correct</p>
  
  <p>Thank you</p>