Results 1 to 6 of 6

Thread: [RESOLVED] Pagination Function

Threaded View

  1. #6

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: [RESOLVED] Pagination Function

    I sure do, I'll explain it a little for people who find it hard to follow my code:

    The software itself is rather huge, but I've posted up a modified snippet of it, where it pulls the data out of the database and paginates it. The example I've provided actually performs the SQL Query twice (One time to get the amount of results, and the second time to get the actual data), but you can use "$numRows = count($currentPageRows);" if you can figure out a way to do so.

    Basically, you just need to add this to your SQL:
    PHP Code:
    if ($currentPage!="all")
    {
      if (
    $currentPage 1)
        {
          
    $currentPage 1;
        } 

        
    $numRowsQueryResult mysql_query($MySQL_Query ";"$dbConn);
        
        
    $numRows mysql_num_rows($numRowsQueryResult);
        
        
    $MySQL_Query .= "LIMIT " . (($currentPage*$numberOfResultsPerPage)-$numberOfResultsPerPage) . ", " $numberOfResultsPerPage;
        
    }


    $currentPageRows mysql_query($MySQL_Query ";"$dbConn); 
    You would get the current page number and place it into "$currentPage" from $_GET.


    Here's what calls the pagination:

    PHP Code:
      if ($currentPage!="all" && ceil($numRows/$numberOfResultsPerPage) >= 1)
      {
        echo 
    "<center>Page: ";
            
            
    $totalPages=ceil($numRows/$numberOfResultsPerPage);
            
            echo 
    printPageIndexes($currentPage$totalPages$myCurrentURL"&page"5true"all");
      } 
    Last edited by Slyke; May 11th, 2009 at 03:32 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
  •  



Click Here to Expand Forum to Full Width