theme_pager and pager_query problems

NateCBarrett - September 11, 2007 - 18:58

I am having problems getting the pager to work correctly. Heres my code...

function viewoffers_page()
{

//Go to the unl db.
db_set_active('unl');

//Create the sql statement to find the info we want.
$sql = "select offer.offer_id as offer_id,
account.name as account_name,
form.name as form_name,
offer.name as offer_name,
offer.full_name as offer_fullname,
offer.url as offer_url,
offer.is_active as offer_is_active,
offer.is_exclusive as offer_is_exclusive,
offer.description as offer_description
from offer left outer join account on (account.account_id = offer.account_id)
left outer join form on (form.form_id = offer.form_id)";

//Set the colspan attribute.
$colspan = 1;

//Create the array of table headers.
$header = array(
array('data' => 'offer_id', 'field' => 'offer_id', 'colspan' => $colspan),
array('data' => 'account_name', 'field' => 'account_name', 'colspan' => $colspan),
array('data' => 'form_name', 'field' => 'form_name', 'colspan' => $colspan),
array('data' => 'offer_name', 'field' => 'offer_name', 'colspan' => $colspan),
array('data' => 'offer_fullname', 'field' => 'offer_fullname', 'colspan' => $colspan),
array('data' => 'offer_url', 'field' => 'offer_url', 'colspan' => $colspan),
array('data' => 'offer_is_active', 'field' => 'offer_is_active', 'colspan' => $colspan),
array('data' => 'offer_is_exclusive', 'field' => 'offer_is_exclusive', 'colspan' => $colspan),
array('data' => 'offer_description', 'field' => 'offer_description', 'colspan' => $colspan),
);

//Create the sql sort clause.
$sql .= tablesort_sql($header);

//Get the paged result set.
$result = pager_query($sql, 1);

//Loop through the result set.
while ($data = db_fetch_object($result))
{
$rows[] = array(
$data->offer_id,
$data->account_name,
$data->form_name,
$data->offer_name,
$data->offer_fullname,
$data->offer_url,
$data->offer_is_active,
$data->offer_is_exclusive,
$data->offer_description
);
}

//Make sure we found some results...
if (!$rows)
{
$rows[] = array(array('data' => t('Empty at the moment..'), 'colspan' => '6'));
}

//Go back to the default db.
db_set_active();

$output .= theme('table', $header, $rows);
$output .= theme('pager', NULL, 50, 0);

return $output;
}

It will display the results with a pager, but not all the results are there. There should be 11 rows or results, but it only is showing 4.

Now if i use:

$result = pager_query($sql, 50);
$output .= theme('pager', NULL, 50, 0);

it will display all the results, but the pager isnt there, (because of the fact that there is only 11 records.)

My question is, how can i limit to 5 records per page, and have it page through ALL the records correctly...

Any help would be GREATLY appreciated,

Thanks,
Nathan Barrett
Nathan@uniqueleads.com

 
 

Drupal is a registered trademark of Dries Buytaert.