title: Sorting html table with a href and php from sql database
body: <p>I have a html table that contains product data from an sql table that is spit out with php. I'd like to sort the data by clicking the heading of the table column.</p>
  
  <p>I'm outputting my table like so (php)</p>
  
  <pre><code>$product_list = "";
  $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC");
  
  $product_list .= "&lt;tr&gt;
        &lt;td&gt;$id&lt;/td&gt;
        &lt;td&gt;&lt;strong&gt;$product_name&lt;/strong&gt;&lt;/td&gt;
        &lt;td&gt;$$price&lt;/td&gt;
        &lt;td&gt;$category&lt;/td&gt;
        &lt;td&gt;$subcategory&lt;/td&gt;
        &lt;td&gt;$date_added&lt;/td&gt;
      &lt;/tr&gt;";
  </code></pre>
  
  <p>Html</p>
  
  <pre><code>&lt;table class="product-list"&gt;
    &lt;tr&gt;
    &lt;th&gt;&lt;a href='?sort=id'&gt;ID&lt;/a&gt;&lt;/th&gt;
    &lt;th&gt;&lt;a href='?sort=product_name'&gt;Name&lt;/a&gt;&lt;/th&gt;
    &lt;th&gt;&lt;a href='?sort=price'&gt;Price&lt;/a&gt;&lt;/th&gt;
    &lt;th&gt;&lt;a href='?sort=category'&gt;Category&lt;/a&gt;&lt;/th&gt;
    &lt;th&gt;&lt;a href='?sort=subcategory'&gt;Subcategory&lt;/a&gt;&lt;/th&gt;
    &lt;th&gt;&lt;a href='?sort=date_added'&gt;Added&lt;/a&gt;&lt;/th&gt;
    &lt;/tr&gt;
    &lt;?php echo stripslashes($product_list); ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I've tried a few ways to do this from examples online but when I click the header nothing happens.</p>
  
  <p>This is something I've tested</p>
  
  <pre><code>$sort = array('id', 'product_name', 'price', 'category', 'subcategory', 'date_added');
  
  $order = '';
    if (isset($_GET['sort']) &amp;&amp; in_array($_GET['sort'], $sort)) {
    $order .= $_GET['sort'];
    }
  
  $query = 'SELECT * FROM products ORDER BY '.$order;
  
  // Then Output the table as above
  </code></pre>
  
  <p>There is a lot happening on the page, I've only included the code that generates and displays the table so it could be something else stopping this but I'd like to make sure I'm going about things the right way before delving into the rest of the code.</p>
  
  <p>Any suggestions how you would go about this would be greatly appreciated.</p>