Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8337325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:16:25+00:00 2026-06-09T04:16:25+00:00

<?php /**************************************************************************** * paging.class.php v 1.0 * * version 1.0 * * This script

  • 0
<?php
/****************************************************************************
* paging.class.php v 1.0
*
* version 1.0
*
* This script allow to generate dynamically navigation of pages on your web site
* It is easy to configure and use this paging class
*
* ----------------------------------------------------------------
*
* You can find examples in the index.php script (with this package)
*

Copyright (C) 2010 Deyan Spasov <deyan@e7studio.com>

*******************************************************************************/

class paging {

    public $showPagesNumber = true;     //Show page number     Example: Page 1 of 20
    public $showPagesForm = true;           //If you want to use pages form. The system show form with input field and go button
    public $showFirstAndLast = true;    //If you have paging buttons first page and last page
    public $showPrevAndNext = true;     //If you have paging button previous page and next page
    public $numberOfPages = 7;              //Set the number of shown pages

    public $pagingClass = 'paging';             //Set css class of your paging
    public $pagingFirstText = '&laquo;';    //Set text of first button
    public $pagingLastText = '&raquo;';     //Set text of last button
    public $pagingPrevText = '&lsaquo;';    //Set text of previous button
    public $pagingNextText = '&rsaquo;';    //Set text of next button
    public $pagingPageText = 'Page';            //Set page text
    public $pagingPageOfText = 'of';            //Set of text
    public $pagingFormButtonText = 'Go';    //Set text of form button


    /*
        Generate standart navigation
        example: generate('?page=', '&category=1', 5, 10, 100)      
        result:  « ‹ 1 2 3 4 5 6 7 8 9 10 › »

        @access public

        @parameters
            $frontUrl - Set the url before page number
            $backUrl  - Set the url after page number
            $currentPage - Set the current page number
            $rowsPerPage - Set how many rows you show on page
            $allRows  - Set the number of all rows that you have

        @return string with paging HTML source code
    */
    public function generate($frontUrl, $backUrl, $currentPage, $rowsPerPage, $allRows) {

        if($allRows <= $rowsPerPage) {
            return '';
        }

        $pages = ceil ( $allRows / $rowsPerPage );

        settype($currentPage, "int");

        if($currentPage < 1 || $currentPage > $pages) {
            $currentPage = 1;
        }

        $paging = '<div class="'.$this->pagingClass.'">';

        if ($currentPage > 2 && $this->showFirstAndLast) {
            $paging .= '<a href="' . $frontUrl . '1' . $backUrl . '" title="First page" class="arrows">'.$this->pagingFirstText.'</a>';
        }

        if ($currentPage > 1 && $this->showPrevAndNext) {
            $paging .= '<a href="' . $frontUrl . '' . ($currentPage - 1) . '' . $backUrl . '" title="Previous page" class="arrows">'.$this->pagingPrevText.'</a>';
        }

        $halfPages = $this->numberOfPages / 2;
        settype($halfPages, 'int');

        if($pages > $this->numberOfPages) {
            if($currentPage == 1) {
                for($i = 1; $i <= $this->numberOfPages; $i ++)
                    $paging .= '<a href="' . $frontUrl . '' . $i . '' . $backUrl . '" ' . (($i == $currentPage) ? ' class="selected"' : ' class="normal"') . '>' . $i . '</a>';
            } elseif ($currentPage == $pages) {
                for($i = $pages - $this->numberOfPages + 1; $i <= $pages; $i ++)
                    $paging .= '<a href="' . $frontUrl . '' . $i . '' . $backUrl . '" ' . (($i == $currentPage) ? ' class="selected"' : ' class="normal"') . '>' . $i . '</a>';
            } else {
                $start = $currentPage - $halfPages;

                if($start == 0) {
                    $start = 1;
                }

                if($start < 1) {
                    $start_at = 1;
                    $end = (- 1) * $start + $halfPages + $currentPage;
                } else {
                    $start_at = $start;
                    $end = $start_at + $this->numberOfPages - 1;
                    if ($end > $pages) {
                        $start_at = $start_at - ($end - $pages);
                        $end = $pages;
                    }
                }

                for($i = $start_at; $i <= $end; $i ++)
                    $paging .= '<a href="' . $frontUrl . '' . $i . '' . $backUrl . '" ' . (($i == $currentPage) ? ' class="selected"' : ' class="normal"') . '>' . $i . '</a>';
            }
        } else {
            for($i = 1; $i <= $pages; $i ++)
                $paging .= '<a href="' . $frontUrl . '' . $i . '' . $backUrl . '" ' . (($i == $currentPage) ? ' class="selected"' : ' class="normal"') . '>' . $i . '</a>';
        }

        if($currentPage < $pages && $this->showPrevAndNext) {
            $paging .= '<a href="' . $frontUrl . '' . ($currentPage + 1) . '' . $backUrl . '"  title="Next page" class="arrows">'.$this->pagingNextText.'</a>';
        }

        if($currentPage + 1 < $pages && $this->showFirstAndLast) {
            $paging .= '<a href="' . $frontUrl . '' . $pages . '' . $backUrl . '" title="Last page" class="arrows">'.$this->pagingLastText.'</a>';
        }

        if($this->showPagesForm) {
            $paging .= '<form method="post" action="" class="page_form">'.$this->pagingPageText.' <input type="text" name="page" value="" /> <button type="submit" name="go_page">'.$this->pagingFormButtonText.'</button></form>';
        }

        if($this->showPagesNumber) {
            $paging .= '<div class="page_numbers">'.$this->pagingPageText.' '.$currentPage.' '.$this->pagingPageOfText.' '.$pages.'</div>';
        }

        $paging .= '<div style="clear: both"></div>';

        return $paging . "</div>";
    }

}

?>

I have this php pagination class and I cannot figure out a way to limit my SQL query. This generates the buttons for pagination just fine, but have no idea how to limit my query output. Also, how would I go about using this class with other variables in my url. because this one doesnt support it I dont think. like.

mypage.php?status=pending&page=4

here is what is in my “working” page.

<?php 

require_once('classes/class.paging.php');

// PAGINATION STUFF
$ordercount1 = mysql_query("SELECT * from orders WHERE technumber='$myuserid'");
$ordercount2 = mysql_num_rows($ordercount1);

// echo $ordercount2;

    $pagingClass = new paging();

    $limit = 10;        //Number of rows that we show on page
    $allRows = $ordercount2;    //Number of all rows that we have

    if(isset($_POST['page'])) {
        $_GET['page'] = $_POST['page'];
    }

    if(!isset($_GET['page']) || !is_numeric($_GET['page'])) {
        $_GET['page'] = 1;
    }

    //We off the page number
    $pagingClass->showPagesNumber = false;
    $pagingClass->showPagesForm = false;
    $pagingClass->numberOfPages = 10;
    echo $pagingClass->generate('?page=', '', $_GET['page'], $limit, $allRows);

// END PAGINATION STUFF

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:16:26+00:00Added an answer on June 9, 2026 at 4:16 am
    • The link you provided show the usage:

      $pages = new Paginator;
      $pages->items_total = $num_rows[0];
      $pages->mid_range = 9;
      $pages->paginate();
      echo $pages->display_pages();

    In this example 9 is the total number of results from your select, use select count(1) from... in order to find this number (total number of results) before you use the Paginator.

    • As for the POST/GET parameters: before you call the paginator loop over the parameters and save them into a string:

    foreach($_GET as $key=> $val){
    $str .= "$key=$val&";}

    Then override the class everytime it creates an HREF for example, change:

    "href=\"{$_SERVER[PHP_SELF]}?page=$i&ipp=$this->items_per_page\">$i</a> "; 
    

    to:

    "href=\"{$_SERVER[PHP_SELF]}?" . $str . "page=$i&ipp=$this->items_per_page\">$i</a> "; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use a paging system like this: <?php $p = $_GET['p']; switch($p) { case
Anyone know how to do paging with php. like this: First 1 2 3
I'm new to OOP. I created this class called Site that is extended but
PHP script to read in user action requests and parse them to their components.
PHP code: echo date(c); //out put like this 2012-06-19T20:37:44+05:30 echo date(d M, Y); //out
PHP experts, I've been working on this problem for about a day and a
PHP version: 5.3.5 Apache version 2 OS: Windows Server 2008 R2 I am trying
i have one php page with paging option i use follwoing sql statement to
how do i implement paging on xml data which is being called through php.
i'm trying to implement paging in xml using this code and got around to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.