title: DataTables Search, Orderby not working
body: <p>This is my server side code:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Helpers;
  
  use PDO;
  use PDOException;
  
  ini_set('display_startup_errors',1);
  ini_set('display_errors',1);
  error_reporting(-1);
  
  
  class DataTables {
  
      private $_db;
  
      public function __construct() {
  
          try {
              $host       = 'localhost';
              $database   = 'zzzzzzzzz';
              $user       = 'xxxxxxxxxxx';
              $passwd     = 'yyyyyyyyyyyyyyyy';
  
              $this-&gt;_db = new PDO('mysql:host='.$host.';dbname='.$database, $user, $passwd, array(PDO::ATTR_PERSISTENT =&gt; true, PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET NAMES 'utf8'"));
          } catch (PDOException $e) {
              error_log("Failed to connect to database: ".$e-&gt;getMessage());
          }
  
      }
  
  
      public function get($table, $index_column, $columns) {
          // Paging
          $sLimit = "LIMIT 1";
          if ( isset( $_GET['start'] ) &amp;&amp; $_GET['length'] != '-1' ) {
              $sLimit = "LIMIT ".intval( $_GET['start'] ).", ".intval( $_GET['length'] );
          }
  
          // Ordering
          $sOrder = '';
          if ( isset($request['order']) &amp;&amp; count($request['order']) ) {
              $orderBy = array();
              $dtColumns = self::pluck( $columns, 'dt' );
              for ( $i=0, $ien=count($request['order']) ; $i&lt;$ien ; $i++ ) {
                  // Convert the column index into the column data property
                  $columnIdx = intval($request['order'][$i]['column']);
                  $requestColumn = $request['columns'][$columnIdx];
                  $columnIdx = array_search( $requestColumn['data'], $dtColumns );
                  $column = $columns[ $columnIdx ];
                  if ( $requestColumn['orderable'] == 'true' ) {
                      $dir = $request['order'][$i]['dir'] === 'asc' ?
                          'ASC' :
                          'DESC';
                      $orderBy[] = '`'.$column['db'].'` '.$dir;
                  }
              }
              $sOrder = 'ORDER BY '.implode(', ', $orderBy);
          }
  
          /*
           * Filtering
           * NOTE this does not match the built-in DataTables filtering which does it
           * word by word on any field. It's possible to do here, but concerned about efficiency
           * on very large tables, and MySQL's regex functionality is very limited
           */
          $sWhere = "";
          if ( isset($_GET['sSearch']) &amp;&amp; $_GET['sSearch'] != "" ) {
              $sWhere = "WHERE (";
              for ( $i=0 ; $i&lt;count($columns) ; $i++ ) {
                  if ( isset($_GET['bSearchable_'.$i]) &amp;&amp; $_GET['bSearchable_'.$i] == "true" ) {
                      $sWhere .= "`".$columns[$i]."` LIKE :search OR ";
                  }
              }
              $sWhere = substr_replace( $sWhere, "", -3 );
              $sWhere .= ')';
          }
  
          // Individual column filtering
          for ( $i=0 ; $i&lt;count($columns) ; $i++ ) {
              if ( isset($_GET['bSearchable_'.$i]) &amp;&amp; $_GET['bSearchable_'.$i] == "true" &amp;&amp; $_GET['sSearch_'.$i] != '' ) {
                  if ( $sWhere == "" ) {
                      $sWhere = "WHERE ";
                  }
                  else {
                      $sWhere .= " AND ";
                  }
                  $sWhere .= "`".$columns[$i]."` LIKE :search".$i." ";
              }
          }
  
          // SQL queries get data to display
          $sQuery = "SELECT SQL_CALC_FOUND_ROWS `".str_replace(" , ", " ", implode("`, `", $columns))."` FROM `".$table."` ".$sWhere." ".$sOrder." ".$sLimit;
          $statement = $this-&gt;_db-&gt;prepare($sQuery);
  
          // Bind parameters
          if ( isset($_GET['sSearch']) &amp;&amp; $_GET['sSearch'] != "" ) {
              $statement-&gt;bindValue(':search', '%'.$_GET['sSearch'].'%', PDO::PARAM_STR);
          }
          for ( $i=0 ; $i&lt;count($columns) ; $i++ ) {
              if ( isset($_GET['bSearchable_'.$i]) &amp;&amp; $_GET['bSearchable_'.$i] == "true" &amp;&amp; $_GET['sSearch_'.$i] != '' ) {
                  $statement-&gt;bindValue(':search'.$i, '%'.$_GET['sSearch_'.$i].'%', PDO::PARAM_STR);
              }
          }
          $statement-&gt;execute();
  
          $iFilteredTotal = current($this-&gt;_db-&gt;query('SELECT FOUND_ROWS()')-&gt;fetch());
  
          // Get total number of rows in table
          $sQuery = "SELECT COUNT(`".$index_column."`) FROM `".$table."`";
          $iTotal = current($this-&gt;_db-&gt;query($sQuery)-&gt;fetch());
  
          // Fetch Results
          $clans = array();
          $rownumber = $_GET['start']+1;
  
          while($clan = $statement-&gt;fetch()){
              $clan['rownumber'] =  intval($rownumber);
              $clans[] = $clan;
              $rownumber++;
          }
  
  
          // Output
          $output = array(
              "draw" =&gt; intval($_GET['draw']),
              "recordsTotal" =&gt; intval($iTotal),
              "recordsFiltered" =&gt; intval($iFilteredTotal),
              "data" =&gt; $clans
          );
  
          echo json_encode((object)$output );
      }
  
  
  }
  
  header('Pragma: no-cache');
  header('Cache-Control: no-store, no-cache, must-revalidate');
  ?&gt;
  </code></pre>
  
  <p>There is a live URL at: <a href="http://clashdata.tk/clans/" rel="nofollow">http://clashdata.tk/clans/</a></p>
  
  <p>Pagination is working fine but if I try to order the columns or sort them then it is giving the normal query for first display. I think I might have the server code wrong. I am using version DataTables version 1.10.10.</p>
  
  <p>Does anyone know what needs to be changed for this to work?</p>
  
  <p>Thanks a lot!</p>