title: Sorting Column by clicking column header in php web page
body: <p>I have one page which has a button that clicks and displays all the data from the database in the table with jquery. I need to sort the table by clicking the column head. problem is that i have is, the way the table is populated.  see the code. I have php code which populates it. The columns are ID, Licence etc. So I need to sort it on based of column. </p>
  
  <pre><code>&lt;?php
  
      $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $query = "
          my query from database to display all the values
                                  ";
                          $result= $dbh-&gt;prepare($query,array(PDO::ATTR_CURSOR =&gt; PDO::CURSOR_SCROLL));
                          $result-&gt;execute();
  
                          echo "&lt;table id='abc' class='abcd' width='100%'&gt;&lt;tr&gt;"
                              . "&lt;th id='mydata' class='myd' onclick='loadOrderedData(myd)'&gt;ABC&lt;/th&gt;"
                              . "&lt;th&gt;DEF&lt;/th&gt;"
                              .......
                              . "&lt;/tr&gt;";
  
                          while($data=$result-&gt;fetch(PDO::FETCH_ASSOC,PDO::FETCH_ORI_NEXT))
                          {
                              echo "&lt;tr&gt;"
                                  . "&lt;td&gt;" . $data['ABC'] . "&lt;/td&gt;"
                                  . "&lt;td&gt;" . $data['DEF'] . "&lt;/td&gt;"
                                  .......
                                  . "&lt;/tr&gt;";
  
                          }
  
                          echo "&lt;/table&gt;";
                      ?&gt;
  </code></pre>
  
  <p>it is displayed in a div which is hidden at first and then using jquery it is made un-hidden on the button click which fetches the data. Please help me with the viable solution.</p>
  
  <p>I tried making <code>&lt;a href="#" &gt;</code> and making use of onclick method. It doesn't work, may be due to how it populates the data. </p>