I have discovered it doesn't get the number of rows correctly when the query contains "GROUP BY" and "SUM()"; so I had to change some code:

	$count_inner = '*';
	if ($table['count_query'] != '') {
		$count_inner = $table['count_query'];
	}
  $count_query = preg_replace('/SELECT (.*) FROM/','SELECT COUNT(' . $count_inner . ') FROM',$table['query']);
  $result = db_query($count_query,$search_values);
  $row = db_fetch_array($result);
  $count = $row['COUNT(' . $count_inner . ')'];
  $elements['rows'] = $count;

replaced by
<?
$res_temp=db_query($table["query"]);
$count=db_num_rows($res_temp);
$elements['rows']=$count;
unset($res_temp);
?>
It may add some overhead to the database server, but it has less PHP code and works.

Comments

enboig’s picture

sorry, my code wasn't included in php tags correctly:

  $res_temp=db_query($table["query"]);
  $count=db_num_rows($res_temp);
  $elements['rows']=$count;
  unset($res_temp);