title: How to implement server-side processing with jQuery DataTables plugin?
body: <p>I am using the jQuery <a href="http://datatables.net" rel="nofollow">DataTables</a> plugin to display a set of results combined from multiple tables.  I am trying to implement <a href="http://datatables.net/examples/data_sources/server_side.html" rel="nofollow">server-side processing</a> through the plugin to improve page load times.  I can't quite figure out how to extrapolate the <a href="http://datatables.net/examples/data_sources/server_side.html" rel="nofollow">example</a> DataTables gives to my scenario.  Any ideas/suggestions?</p>
  
  <p>Javascript:</p>
  
  <pre><code>$('#results').dataTable({
          "sAjaxSource": "../server_processing.php",  
          "bProcessing": true,
          "bServerSide": true,
          "bDeferRender": false, 
  })
  </code></pre>
  
  <p>Original PHP Function:</p>
  
  <pre><code>function build_data_list(){
  
      global $org_id;
      global $dbh;
      global $req_ids;
      global $user_list;
  
      $sth = $dbh-&gt;query ("SELECT 
                          l4.name as L4name, 
                          l3.name as L3name, 
                          l2.name as L2name, 
                          l1.name as L1name,
                          u.id,
                          u.last_name,
                          u.first_name,
                          FROM user_grp_indx ugi, groups l4, groups l3, groups l2, groups l1, users p
                          WHERE
                          ugi.user_id = u.id
                          AND l4.id =  ugi.grp_id
                          AND l4.parent = l3.id
                          AND l3.parent = l2.id
                          AND l2.parent = l1.id
                          ORDER BY u.id", PDO::FETCH_ASSOC);
  
      $row = $sth-&gt;fetch();
  
      $item['user_id'] =  $row['id'];
  
      $item['user_info'] = '&lt;a href="../users/index.php?pq=';
      $item['user_info'] .= $row['id'].'"&gt;';
      $item['user_info'] .= $row['last_name']. ", " . $row['first_name'] . "&lt;/a&gt;";    
  
      $item['l1_name'] = $row['L1name'];
      $item['l2_name'] = $row['L2name'];
      $item['l3_name'] = $row['L3name'];
      $item['l4_name'] = $row['L4name'];
  
      for ($i=0; $i &lt; sizeof($req_ids) ; $i++ ){
              $item['req'.$i] = (chk_req_status($item['user_id'],$req_ids[$i]) ? "&lt;span title=\"Yes\"&gt;&lt;/span&gt;&lt;img src=\"../../media/icons/tick.png\" alt=\"Yes\" /&gt;" :
                                                      "&lt;span title=\"No\"&gt;&lt;/span&gt;&lt;img src=\"../../media/icons/cross.png\" alt=\"No\" /&gt;");
      }
  
      $old_L1id = $row['L1id'];
      $old_user_id = $row['id'];
  
      while ($row = $sth-&gt;fetch()){
  
          $L1id =  $row['L1id'];
          $user_id =  $row['id'];
  
          if ($L1id == $old_L1id &amp;&amp; $user_id == $old_user_id ){
  
              $item['l2_name'] .= "&lt;br/&gt;" . $row['L2name'];
              $item['l3_name'] .= "&lt;br/&gt;" . $row['L3name'];
              $item['l4_name'] .= "&lt;br/&gt;" . $row['L4name'];
  
              continue;
  
          }   
  
          $user_list[] = $item;     
          $old_L1id = $L1id; 
          $old_user_id = $user_id;
  
          $item['user_id'] =  $row['id'];
  
          $item['user_info'] = '&lt;a href="../users/index.php?pq=';
          $item['user_info'] .= $row['id'].'"&gt;';
          $item['user_info'] .= $row['last_name']. ", " . $row['first_name'] . "&lt;/a&gt;";  
  
          //add inital level stuff to the new record.
          $item['l1_name'] = $row['L1name'];
          $item['l2_name'] = $row['L2name'];
          $item['l3_name'] = $row['L3name'];
          $item['l4_name'] = $row['L4name'];  
  
          for ($i=0; $i &lt; sizeof($req_ids) ; $i++ ){
              $item['req'.$i] = (chk_req_status($item['user_id'],$req_ids[$i]) ? "&lt;span title=\"Yes\"&gt;&lt;/span&gt;&lt;img src=\"../../media/icons/tick.png\" alt=\"Yes\" /&gt;" :
                                                      "&lt;span title=\"No\"&gt;&lt;/span&gt;&lt;img src=\"../../media/icons/cross.png\" alt=\"No\" /&gt;");
          }
  
      }
  
  }
  </code></pre>
  
  <p>Original HTML/PHP:</p>
  
  <pre><code>&lt;tbody&gt;
      &lt;?php foreach($user_list as $item){
  
          print "&lt;tr&gt;";
          print "&lt;td class=\"hidden\"&gt;{$item['user_id']}&lt;/td&gt;";
          print "&lt;td&gt;{$item['user_info']}&lt;/td&gt;";
          print "&lt;td&gt;{$item['l1_name']}&lt;/td&gt;";
          print "&lt;td&gt;{$item['l2_name']}&lt;/td&gt;";
          print "&lt;td&gt;{$item['l3_name']}&lt;/td&gt;";
          print "&lt;td&gt;{$item['l4_name']}&lt;/td&gt;";
  
          for ($i=0; $i &lt; sizeof($req_ids) ; $i++ ){
              print '&lt;td&gt;'.(  chk_req_status($item['user_id'],$req_ids[$i]) ? "&lt;span title=\"Yes\"&gt;&lt;/span&gt;&lt;img src=\"../../media/icons/tick.png\" alt=\"Yes\" /&gt;":
                  "&lt;span title=\"No\"&gt;&lt;/span&gt;&lt;img src=\"../../media/icons/cross.png\" alt=\"No\" /&gt;").'&lt;/td&gt;';
          }
  
          print "&lt;/tr&gt;";  
  
      } ?&gt;
  &lt;/tbody&gt;
  </code></pre>