Table with sqlsrv driver is not showing headers or pagination I just wanted to practice doing the table "header sorting" and pagination to display a Drupal 6 table using a simple MSSQL query. At the moment, the table headers are not showing and there is no pagination, but the data in the query is being displayed. Can anyone see anything wrong with the code?

/* open database connection */
include "mssqlconnection.inc.php";

/* set up the table headers */
$headers = array(
  '',
  array('image_id' =&gt; t('image_id'), 'field' =&gt; 'image_id', 'sort'=&gt;'asc'),
  array('geo_post' =&gt; t('geo_post'), 'field' =&gt; 'geo_post'),
  array('geo_sample' =&gt; t('geo_sample'), 'field' =&gt; 'geo_sample'),
  array('gps_lat' =&gt; t('geo_lat'), 'field' =&gt; 'geo_lat'),
  array('gps_long' =&gt; t('gps_long'), 'field' =&gt; 'gps_long'),
  ''
);


/* Set up and execute the query. */
$sql = sprintf ("SELECT TOP 100 image_id,
  geo_post,
  geo_sample,
  gps_lat,
  gps_long,
  FROM images"
);

/* add the order by clause */
$stmt .= tablesort_sql($headers);

$stmt = sqlsrv_query($conn, $sql);
if ( $stmt === false) {
  echo "Error in query preparation/execution.\n";
  die( print_r( sqlsrv_errors(), true));
}

/* collecting results */

while ($doc = sqlsrv_fetch_object($stmt)) {
  $rows[] = array(
    sprintf($imgPublish . '&amp;nbsp;&amp;nbsp;&amp;nbsp;' . $imgDelete, $doc-&gt;nid),
    $doc-&gt;image_id,
    $doc-&gt;geo_post,
    $doc-&gt;geo_sample,
    doc-&gt;gps_lat,
    $doc-&gt;gps_long
  );
}

$table = theme('table', $headers, $rows);
$table .= theme('pager', array(), 10, 0);

return $table;    

/* Close the connection. */
include "closemssqlconnection.inc.php";
theme_pager() only works in combination with pager_query() (Or the PagerDefault extender in Drupal 7). And that function is obviously not going to work with sqlsrv().

For Drupal 7, there is the http://drupal.org/project/sqlsrv project, which is properly integrated into the new database abstraction layer. I suggest you have a look at the following answer to see how you might be able to use that in Drupal 6: MSSql or SQL Server Wrapper for custom module? See also How do you make sortable tables with a pager with data from a custom table? for how to create paginated queries with Drupal 7/the DBTNG project.