How to write a simple pager_query in Drupal that is sortable?

<?php

$list[]=array(”);
$rows[] = array(”);
$header = array(array(‘data’=>t(‘Title’),’field’=>’n.title’), array(‘data’=>t(‘Referral Author’),’field’=>’n.uid’), array(‘data’=>t(‘Time Created’),’field’=>’n.created’, ‘sort’ => ‘asc’), ‘Average Rating’);

$res = “SELECT n.title,n.nid, n.uid, n.created from {content_type_referral} cr join {node} n on cr.nid=n.nid and cr.vid=n.vid where n.type=’referral’ and n.status=1 “.tablesort_sql($header);

$count_query = “SELECT count(*) from {content_type_referral} s join {node}   n on s.nid=n.nid and s.vid=n.vid”;Movie A Dog’s Purpose (2017)

$result_set = pager_query($res, 10, 0, $count_query);

while ($obj = db_fetch_object($result_set)){

$rows[] = array(l($obj->title, “node/”.$obj->nid), $obj->uid, strftime (“%A, %d. %B %Y”, $obj->created));

}

$output = theme(‘table’, $header, $rows);
$output .= theme(‘pager’, NULL, 10, 0);
print $output;

?>

css.php