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 8792583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:59:56+00:00 2026-06-13T22:59:56+00:00

Anyone know a good place or a good tutorial how to set up this

  • 0

Anyone know a good place or a good tutorial how to set up this pagination I’m looking for?

Before you get mad that I’m posting hundreds of lines here, let me just give a fast explaination about what I want to achieve, the codes I use to explain my situation better.

The code below works if you only want to paginate or only want to search:
1. Enter the main page, and the pagination works. Hit page 1, page 2, etc and you get the result you are expecting.
2. Use the search, and it works, but this gives ALL records without limitation in 1 page. I could set up a limit but the pagination still will not work.

I just don’t know how to get the search variable and add it to the pagination.

Is it possible to have an url like: search=Hello+World?orderby=custforename+custsurname?page=3..I think it is… How is something like this, ‘?nested get variables?’ called? Anyone knows a good place around for an advanced pagination tutorial?


I’m using this code on my main page:

<?php
    if(isset($_POST['search']))
    {
        $search = $_POST['search'];
        $search = ltrim($search, " ");
        $terms = explode(" ", $search);
        $customerlistquery = "
                            SELECT *
                            FROM customer
                            LEFT JOIN company
                            ON customer.compid=company.compid
                            WHERE
                            ";
        $i = 0;
        foreach ($terms as $each) 
        {
            if ($i++ > 0) 
            $customerlistquery .= ' OR ';

            $customerlistquery .= "concat(custsurname, custforename, custmidname, custpostal, custphone1, custphone2, custfax, custnamecode, datemodified, modifiedby) LIKE '%$each%' ";
        }
        $customerlistquery .= " ORDER BY $orderby ASC";
    }
    else
    {
        $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
        $startpoint = ($page * $limit) - $limit;
        $customerlistquery = "  
                SELECT *
                FROM customer
                LEFT JOIN company
                ON customer.compid=company.compid
                ORDER BY $orderby ASC 
                LIMIT {$startpoint}, {$limit}
                ";
        echo pagination("customer
                LEFT JOIN company
                ON customer.compid=company.compid
                ORDER BY $orderby ASC",$limit,$page);       
    }
?>


$result=mysql_query($itemslistquery) or die("query fout " . mysql_error() );

And at last the pagination.php code:

<?php
    function pagination($query, $per_page = 10,$page = 1, $url = '?'){        
        $query = "SELECT COUNT(*) as `num` FROM {$query}";
        $row = mysql_fetch_array(mysql_query($query));
        $total = $row['num'];
        $adjacents = "2"; 

        $page = ($page == 0 ? 1 : $page);  
        $start = ($page - 1) * $per_page;                               

        $prev = $page - 1;                          
        $next = $page + 1;
        $lastpage = ceil($total/$per_page);
        $lpm1 = $lastpage - 1;

        $pagination = "";
        if($lastpage > 1)
        {   
            $pagination .= "<ul class='pagination'>";
                    $pagination .= "<li class='details'>Page $page of $lastpage</li>";
            if ($lastpage < 7 + ($adjacents * 2))
            {   
                for ($counter = 1; $counter <= $lastpage; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<li><a class='current'>$counter</a></li>";
                    else
                        $pagination.= "<li><a href='{$url}page=$counter'>$counter</a></li>";                    
                }
            }
            elseif($lastpage > 5 + ($adjacents * 2))
            {
                if($page < 1 + ($adjacents * 2))     
                {
                    for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                    {
                        if ($counter == $page)
                            $pagination.= "<li><a class='current'>$counter</a></li>";
                        else
                            $pagination.= "<li><a href='{$url}page=$counter'>$counter</a></li>";                    
                    }
                    $pagination.= "<li class='dot'>...</li>";
                    $pagination.= "<li><a href='{$url}page=$lpm1'>$lpm1</a></li>";
                    $pagination.= "<li><a href='{$url}page=$lastpage'>$lastpage</a></li>";      
                }
                elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
                {
                    $pagination.= "<li><a href='{$url}page=1'>1</a></li>";
                    $pagination.= "<li><a href='{$url}page=2'>2</a></li>";
                    $pagination.= "<li class='dot'>...</li>";
                    for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
                    {
                        if ($counter == $page)
                            $pagination.= "<li><a class='current'>$counter</a></li>";
                        else
                            $pagination.= "<li><a href='{$url}page=$counter'>$counter</a></li>";                    
                    }
                    $pagination.= "<li class='dot'>..</li>";
                    $pagination.= "<li><a href='{$url}page=$lpm1'>$lpm1</a></li>";
                    $pagination.= "<li><a href='{$url}page=$lastpage'>$lastpage</a></li>";      
                }
                else
                {
                    $pagination.= "<li><a href='{$url}page=1'>1</a></li>";
                    $pagination.= "<li><a href='{$url}page=2'>2</a></li>";
                    $pagination.= "<li class='dot'>..</li>";
                    for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
                    {
                        if ($counter == $page)
                            $pagination.= "<li><a class='current'>$counter</a></li>";
                        else
                            $pagination.= "<li><a href='{$url}page=$counter'>$counter</a></li>";                    
                    }
                }
            }

            if ($page < $counter - 1){ 
                $pagination.= "<li><a href='{$url}page=$next'>Next</a></li>";
                $pagination.= "<li><a href='{$url}page=$lastpage'>Last</a></li>";
            }else{
                $pagination.= "<li><a class='current'>Next</a></li>";
                $pagination.= "<li><a class='current'>Last</a></li>";
            }
            $pagination.= "</ul>\n";      
        }


        return $pagination;
    } 
?>
  • 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-13T22:59:57+00:00Added an answer on June 13, 2026 at 10:59 pm

    If you want to pass more than 1 variable with GET, you have to use it like this:

    url?var1=x&var2=y&var3=z

    In PHP you would recover them like this:

    $var1=$_GET['var1'];
    $var2=$_GET['var2'];
    $var3=$_GET['var3'];
    

    About your ‘paginator’ problem, I usually only do 1 query and then paginate it with javascript on the client side, this way I can change pages without waiting for the server to answer.

    If you want to do it with PHP only, you should set ‘LIMIT x,y’ on your query, where x is the first element of the page, and y the number of elements you want to show in one page. For example, if you are showing pages of 50 elements:

    $x=50*($pagenumber-1); //the index of the 1st element is 0
    $y=50;
    $query="SELECT * FROM table LIMIT $x,$y";
    

    Something like this should work just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of a good place to get a csv spreadsheet of some
First off, does anyone know of a good place to get help with CodeIgniter?
Does anyone know of a good place that has some HTML templates for database
Does anyone know a good place to look for basic principles and tutorials on
Does anyone know any good resources with tasks or problems to get practice in
Anyone know of a good beginners tutorial for Turbogears 2? I'm particularly interested in
Does anyone know a good place to learn css? When I say css I
Does anyone know of a good free alternative to Project Place ?
I don't know if this is the right place to ask about that, but
Does anyone know a good place to learn how to implement shadows in openGL?

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.