title: ORDER BY column_name help (via link in HTML table view) (PHP MySQL
body: <p>My output for my table in HTML has several columns such as userid, name, age, dob.</p>
  
  <p>The table heading is simply the title of the column name, I want this to be a link, and when clicked, the selected column is sorted in order, ASC, and then DESC (on next click). I thought this was pretty straight forward but I'm having some difficulty.</p>
  
  <p>So far, I have produced this, and no output is taken, apart from the URL works by displaying 'users.php?orderby=userid'</p>
  
  <pre><code>&lt;?php
            if(isset($_GET['orderby'])){ 
  $orderby = $_GET['orderby']; 
  $query_sv = "SELECT * FROM users BY ".mysql_real_escape_string($orderby)." ASC"; 
  } 
  //default query 
  else{ 
  $query_sv = "SELECT * FROM users BY user_id DESC"; 
  } 
  ?&gt;
  
  
                &lt;tr&gt;
                  &lt;th&gt;&lt;a href="&lt;?php echo $_SERVER['php_SELF']."?orderby=userid";?&gt;"&gt;User ID&lt;/a&gt;&lt;/th&gt;
  </code></pre>
  
  <p>Hoefully if I get this working, I can sort the users by D.O.B. next also using the same principles. Does anyone have any ideas?</p>