I have a custom callback function that queries data from a custom table.
The trimmed version of code that I have been writing looks as below,
function cb_user_cashback_orders($account) {
$sql = 'SOME SQL QUERY';
$results = db_query($sql, array(':uid' => $account->uid));
//date, Merchant name, commission, status
$header = array(t('Date'), t('Merchant Name'), t('Commission'), t('Status'));
$rows = array();
foreach ($results as $result) {
$rows[] = array(
format_date($result->timestamp),
$result->status ? l($result->title, "node/{$result->merchant_nid}") : $result->title,
$result->commission,
$result->status,
);
}
pager_default_initialize(count($rows), 10, 0); // Pager doesn't appear without this call
$output = theme('table', array(
'header' => $header,
'rows' => $rows,
'empty' => t('You have not made any purchase yet.'),
'attributes' => array('class' => array('cb-user-orders')),
)
);
$output .= theme('pager'); // as a replacement for pager_query() in D6.
return $output;
}
I'm trying to figure out how I could get the pager work as expected.
With the code above I'm able to get the pager links (first, next, last, etc.) however the table always show the same set of items (infact all items) irrespective of pager argument (?page=1,2 OR N).
Would like to hear some input to fix this. Is theme('pager') designed to work only with dynamic query?