In includes/pager.inc, there is a preg_replace() that modifies SQL queries to count the results. However, the preg_replace() does not allow for endlines in the SQL, so it does not count correctly. Why would there be endlines in the SQL? Because some people like to organize complex statements onto for simplified viewing.

So instead of:

$pager_total[$element] = db_result(db_query(preg_replace(array("/SELECT.*FROM/i", "/ORDER BY .*/"), array("SELECT COUNT(*) FROM", ""), $query)));

do:

$pager_total[$element] = db_result(db_query(preg_replace(array("/SELECT.*FROM/is", "/ORDER BY .*/"), array("SELECT COUNT(*) FROM", ""), $query)));

The /s modifier allows the .* to match endlines.

(Do I really have to submit a patch for this?)

Comments

Dries’s picture

Changed in HEAD. Thanks.

Anonymous’s picture