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

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


<?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";

  $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;

?>

                                     
2 points

Thank you for your post.

Anonymous's picture
Created by Anonymous

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.