Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    422
    Thanks
    8
    Thanked 6 Times in 6 Posts

    Slow Pagination (potentially) - Is there a better way?

    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:
    PHP 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
    Last edited by mOrloff; 03-19-2009 at 05:49 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •