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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:20:47+00:00 2026-06-13T09:20:47+00:00

So I have an example of a query that was graciously provided by Frost

  • 0

So I have an example of a query that was graciously provided by Frost which has helped me learn SO much ( I am very much a newbie) but I am stuck trying to add pagination. I have been scouring the web for a week now and there are so many different examples and I have tried so many of them with little or no success. I was finally able to build what you see below, the problem is that when you hit search it does indeed only return 20 records but the pages don’t work. The way they dont work is that when you click ‘next’ it will go to page two but no results show up, and if you click again expecting page 3 it wont go there it stays on page 2. I really did not want to take anyone’s valuable time but I am just so very lost. Here is “my” code:

    <?php

    //we select all the License records
    $req_limit = mysql_query("Select License from OPLR");
    $result = mysql_numrows($req_limit);//mysql_numrows() give us the result of the     request

    // now we will use the result to limit the displayed messages
    $page_limit = '20'; //we chose the number of messages by page
    // here we divide the total by the number of messages we choose
    $page_number = $result / $page_limit; 

    // we round the number of pages to avoid commas.
    $total_number = ceil($page_number); 

    // here we take of one page because the first page will be displyed is number one
    $number = $total_number - 1; 

    // if the variable number_page is equal or defferent to 0
    if(isset($_GET['page_number']) || $_GET['page_number'] != '0' ) 

    {
    // multiplies the page limit with the current number page on the url
    $mysql_limit = $page_limit * $_GET['page_number']; 

    }
    else{ // no variable number_page

    $mysql_limit = '0'; // the limit is 0

    }

    ?>

    <?php
    /*****************************
     *  Simple SQL Search Tutorial by Frost
     *  of Slunked.com
     ******************************/



    // Set up our error check and result check array
    $error = array();
    $results = array();

    // First check if a form was submitted. 
    // Since this is a search we will use $_GET
    if (isset($_GET['search'])) {
       $searchTerms = trim($_GET['search']);
       $searchTerms = strip_tags($searchTerms); // remove any html/javascript.

       if (strlen($searchTerms) < 0) {
  $error[] = "Search terms must be longer than 3 characters.";
       }else {
          $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql         injection.
       }

       // If there are no errors, lets get the search going.
               if (count($error) < 1) {

          $searchSQL = "SELECT License, Pet_Name, Owner_Name, Species, Notes, Unowned FROM OPLR WHERE ";

  // grab the search types.
  $types = array();
  $types[] = isset($_GET['License'])?"`License` LIKE '%{$searchTermDB}%'":'';
  $types[] = isset($_GET['Pet_Name'])?"`Pet_Name` LIKE '%{$searchTermDB}%'":'';
  $types[] = isset($_GET['Owner_Name'])?"`Owner_Name` LIKE '%{$searchTermDB}%'":'';
  $types[] = isset($_GET['Species'])?"`Species` LIKE '%{$searchTermDB}%'":'';
  $types[] = isset($_GET['Unowned'])?"`Unowned` LIKE 'y'":'';

   $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked)

  if (count($types) < 1)
     $types[] = "`Pet_Name` LIKE '%{$searchTermDB}%'"; // use the Pet_Name as a default search if none are checked

      $andOr = isset($_GET['matchall'])?'AND':'OR';


  $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `Pet_Name`"; // order by Pet Name.

  $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>"         . mysql_error() . "<br 

    />SQL Was: {$searchSQL}");

  if (mysql_num_rows($searchResult) < 1) {
     $error[] = "The search term provided {$searchTerms} yielded no results.";
  }else {
     $results = array(); // the result array
     $i = 1;
     while ($row = mysql_fetch_assoc($searchResult)) {
        $results[] = "<B>License Number: {$row['License']}</B><br />Pet Name: {$row['Pet_Name']}<br /> Owner Name: {$row['Owner_Name']}<br />Species: {$row['Species']}<br />Notes: {$row['Notes']}<br /><br />";
        $i++;
     }
  }
       }
    }


    ?>
    <?php echo (count($error) > 0)?"The following had errors:<br /><span         id=\"error\">" . implode("<br />", 

    $error) . "</span><br /><br />":""; ?>
       <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>"         name="searchForm" id="searchform">

           <fieldset>
     <center><p>Search For:
     <input type="text" name="search" value="<?php echo         isset($searchTerms)?htmlspecialchars

    ($searchTerms):''; ?>" /></p></center>
   </fieldset>




         <fieldset>


     <div id="checks"><center>
       License Number: 
       <input type="checkbox" name="License" value="on" <?php echo         isset($_GET['License'])?"checked":''; ?> />      
       |    


     Species: 
       <input type="checkbox" name="Species" value="on" <?php echo         isset($_GET['Species'])?"checked":''; ?> /> 
        |  &nbsp;     
     Unowned: 
     <input type="checkbox" name="Unowned" value="on" <?php echo         isset($_GET['Unowned'])?"checked":''; ?> />
     <br />
             Match All Selected Fields? <input type="checkbox" name="matchall"         value="on" <?php echo isset($_GET['matchall'])?"checked":''; ?> />
 <br /><br />

     <input type="submit" name="submit" value="Search!" /></center></div>
 </fieldset>
       </form>
       <?php echo (count($error) >         0)?"The following had errors:<br /><span         id=\"error\">" .   implode("<br />", 

    $error) . "</span><br /><br />":""; ?>

      <?php echo (count($results) > 0)?"Your search: {$searchTerms} <br> <b>Returned:        </b><br /><br />" . implode("", 

    $results):""; 
    ?>
    <?php
    // If the page number different of 0 and if the page_number is unset
    if( $number != '0' && empty($_GET['page_number']))
    {
    print '<a href="registry.php?page_number=1">Next page</a>'; // we set the         page_number to 1
    }

    // in this condition, the variable page_number is set and its value is less than         $number
    elseif($number !='0' && isset($_GET['page_number']) && $_GET['page_number']         <             $number)
    {
           $next = $_GET['page_number'] + 1; // add 1 to the current page number
    print '<a href="registry.php?page_number='.$suivant.'">next page</a>'; //The link         for the next pages
    // go back to the precedent page, we used a java-script code to do it print         '&nbsp;&nbsp;<a href="javascript: history.back();">Previous page</a>';
    }

    // here, the link that will be displayed when the page number is reched
    elseif( $number !='0' && isset($_GET['page_number']) && $_GET['page_number'] >= $number )
    {
    print '<a href="javascript: history.back();">Previous page</a>';
    }
    function removeEmpty($var) {
       return (!empty($var)); 
    }
    ?>
  • 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-13T09:20:48+00:00Added an answer on June 13, 2026 at 9:20 am

    You have multiple problems. First one is that you use a form submit to get the values from the options (which is fine) but the link “next page” just gives a page_id and not all the other options. (You could either put them in the next link (as you use _GET anyways) or store the submitted values in a sessionn. I’d prefer the latter).

    The other problem is, that you do some pagination calculation, but u never use the number you calculated. You have to put in an mysql LIMIT statement. ( There right point for that would be after the “ORDER BY”. For that replace

    " ORDER BY `Pet_Name`";
    

    by

    " ORDER BY `Pet_Name` LIMIT ". $mysql_limit .",". $page_limit;
    

    But remember, this will only fix problem 2, you still have to put those _GET Variables into the “next page”

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

Sidebar

Related Questions

For example I have a mysql query that gets some data. Then runs another
I have a query that searches for clients using like with wildcard. For example:
Good morning, mysql query which displays cases that have a date field completed &
For example I have a mysql_num_rows results of 4,8,15,16,23,42 in a query that is
I have a SQL query that takes a very long time to run on
If you have for example > 5 left joins in a query is that
Ok, I have an example table with the following information and query. First up
i have a recursive query like this (note: this is just an example): var
I have the following query in VBA: DoCmd.RunSQL INSERT INTO table (value) VALUES ('example')
We have a Union Query. Here's a basic (similar) example: SELECT a.Name, b.Info FROM

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.