...

View Full Version : Slow Pagination (potentially) - Is there a better way?



mOrloff
03-19-2009, 05:29 PM
I still count myself as a newbie, so my approach (and code) are on the simple side.
Now, I'm a big fan of "Why think zebra when donkey will do", so simple suits me, but not at the expense of performance.

Right now, I am running my query (using my custom qry func), generating my pagination vars from those results, then re-running the query using the pagination vars.

Is there a better way of doing this (like maybe not running the qry twice)?

Here's a snippet of my code:


$dataset=qryFunc($select,$from,$where,$order,$group,$limit);

$rows = mysql_num_rows($dataset);
define("pageRows",25);
$lastPg=ceil($rows/pageRows);
if(isset($_GET["pagenum"])){$pagenum=$_GET["pagenum"];}else{$pagenum=1;}
if($pagenum<1){$pagenum=1;}elseif($pagenum>$lastPg){$pagenum=$lastPg;}
$limit=($pagenum - 1)*pageRows.",".pageRows;

$dataset=qryFunc($select,$from,$where,$order,$group,$limit);


~ Mo



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum