title: Sort MYSQL TABLES using PHP
body: <p>I have a table that sorts the name by ASC order but when i click the button it doesn't work. 
  I tried doing the same with 2 buttons and checked some of the codes available but it doesn't work at all. Any help?</p>
  
  <p>PHP Code:</p>
  
  <pre><code>&lt;?php
      $servername = "localhost";
      $username = "root";
      $password = "";
      $dbname = "myfeeds";
  
      $conn = mysql_connect($servername, $username, $password, $dbname);
      if (!$conn) {
          die("Connection failed");
      }
  
      $db = mysql_select_db("myfeeds", $conn);
      if (!$db) {
          die("Can't select database");
      }
  
      if (isset($_POST['asc'])) {
          $result = mysql_query("SELECT * FROM websites ORDER BY name ASC");
      } else {
          $result = mysql_query("SELECT * FROM websites ORDER BY name DESC");
  
      }
  
      if (!$result) {
          die("Failed to show queries from table");
      }
  
  
      $num = mysql_numrows($result);
      mysql_close();
      ?&gt;
  </code></pre>
  
  <p>Here's the button:</p>
  
  <pre><code>SORT BY:  
              &lt;form method="POST" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
                  &lt;button type="submit" id="asc" name="asc"&gt;ASC&lt;/button&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>Table: </p>
  
  <pre><code>                    &lt;table cellpadding="0"&gt;
                      &lt;tr&gt;
                          &lt;th&gt;ID&lt;/th&gt;
                          &lt;th&gt;Name&lt;/th&gt;
                          &lt;th&gt;URL&lt;/th&gt;
                          &lt;th&gt;Description&lt;/th&gt;
                          &lt;th&gt;Logo&lt;/th&gt;
                      &lt;/tr&gt;
  
                      &lt;?php
                      $i = 0;
  
                      while ($i &lt; $num) {
                          $f5 = mysql_result($result, $i, "id");
                          $f1 = mysql_result($result, $i, "name");
                          $f2 = mysql_result($result, $i, "url");
                          $f3 = mysql_result($result, $i, "description");
                          $f4 = mysql_result($result, $i, "image");
                          ?&gt;
                          &lt;tr&gt;
                              &lt;td&gt;&lt;?php echo $f5; ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo $f1; ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo $f2; ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo $f3; ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo "&lt;img src='$f4'&gt;"; ?&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;?php
                          $i++;
                      }
                      ?&gt;
                  &lt;/table&gt;
  </code></pre>