Query loses actual total number of rows after pagination

omerida - March 27, 2008 - 19:01
Project:Views Alpha Pager
Version:5.x-1.3
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I'm using alpha pager to break up a list of user profiles by last name, but still want to display the total number of users at the top of my view. This module replaces $view->total_rows with the number of rows that match a specific letter. The code below adds a propert named alpha_pre_total_rows to the view with the original count of matching rows for the view before pagination.

@@ -115,6 +115,13 @@
return;
}

+ $total_rows_query = preg_replace('/^SELECT(.*)FROM/',
+ 'SELECT COUNT(' . $query->count_field . ') as `total` FROM',
+ $query->query());
+ $total_rows_query = preg_replace('/\s+ORDER BY.*$/', '', $total_rows_query);
+ $result = db_query($total_rows_query, $query->where_args);
+ $total_rows = db_fetch_object($result);
+
// NOTE: if the sort field isn't alpha, the results don't make sense
// NOTE: should we remove this check and just always look for fields first
if ($view->page_type == 'table' || $view->page_type == 'search') {
@@ -219,6 +226,7 @@
$placements = array('both', 'top', 'bottom');
$view->alpha_pager_placement = $placements[$placement - 2];
$view->alpha_pager_output = theme('alpha_pager', $items, $apage, $link);
+ $view->alpha_pre_total_rows = $total_rows->total;
}

function _views_alpha_pager_build_query(&$view) {

#1

gionnibgud - August 11, 2008 - 11:01

Hey this was really useful!!

cheers

 
 

Drupal is a registered trademark of Dries Buytaert.