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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:00:42+00:00 2026-06-13T03:00:42+00:00

It’s been a month and am really messed up trying to integrate a php

  • 0

It’s been a month and am really messed up trying to integrate a php pagination code to my search script. Referred to most of the tutorials Googling, but in vain. Any help would be much appreciated. Here I go…

<?php
 ob_start();
 session_start();
 $_GET['term'] = trim($_GET['term']);
 $output = preg_replace('!\s+!', ' ', $_GET['term']);
 if(empty($_GET['term'])|| preg_match("/^[@!#\$\^%&*()+=\-\[\]\\\';,\.\/\{\}\|\":<>\?\ _ ]+$/i", $_GET['term']) || $output== ' ' || $_GET['term']== "%24_GET%5B%27term%27%5D")
 {
 echo "<BR>";
 echo "<BR>";
 echo("Please enter a Valid Search term");
 }
 else
 {
    mysql_connect("localhost", "root", "root");
    mysql_select_db("search");
    $_GET['term'] = explode(' ', $_GET['term']);
    foreach($_GET['term'] AS $_GET['term'])
     {
     $_GET['term'] = trim($_GET['term']);
 $sql = mysql_query("SELECT DISTINCT * FROM searchengine WHERE pagecontent LIKE '%" . str_replace(' ', "%' AND pagecontent LIKE '%", $_GET['term'])."%' LIMIT 0,10");
   while($ser = mysql_fetch_array($sql)) {
       echo "<BR>";
        echo "<b><u><a href='$ser[pageurl]'>$ser[title]</a></u></b>";
        echo "<BR>";
        echo("<span class='style_block'>{$ser['pagecontent']}</span>");
        echo "<BR>";
        echo ("<a href='$ser[pageurl]'>$ser[pageurl]</a>");
        echo "<BR>";
        echo "<BR>";
       } 
    }
$count=mysql_num_rows($sql);
if($count==0)
{
 echo "<BR>";
 echo "<BR>";
echo "Sorry, No News material was found... Please refine your search criteria and try again.";
}
    }
?>
  • 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-13T03:00:43+00:00Added an answer on June 13, 2026 at 3:00 am

    Apart from the problems Luc M has mentioned in his comment (which you should certainly resolve before moving forward), you are almost there.

    You need to consider a couple of points, really: How many records to display per page, and what page you are on. These will dictate the records you need to retrieve and display. So, how do you go about this?

    The first point is covered in your code already through use of the LIMIT clause in your SQL query. The second point is a tiny bit more complex to start with. You need a way of identifying the page you are on. This is probably easiest to identify through a GET variable, for example http://site.com/search.php?page=2. Now, for implementing this, you want something along these lines:

    $recordsPerPage = 10; // although you may want to have this as a GET or POST variable as well, so the user can decide
    if(isset($_GET['page']) // this ensures a default value
    {
        $currentPage = $_GET['page'];
    }
    else
    {
        $currentPage = 1;
    }
    

    Then, for your SQL query, you want to build something like this:

    $query = "SELECT * FROM table_name LIMIT " . $recordsPerPage . " OFFSET " . ($currentPage - 1)*$recordsPerpage . ";";
    

    The OFFSET clause of SQL along with LIMIT basically says “Select this many records, starting from result number x”. You offset on $currentPage - 1 because the first page doesn’t want an offset, and the second page only wants an offset of however many records were shown on the first page, so on and so forth.

    To create navigation for the paginated data, you want to find out how many records are in your result set, which can be done through the count($array) function of PHP. Then, to find the number of pages, simply use something like:

    $numPages = ceil(count($array)/$recordsPerPage);

    Where $array is your dataset from the SQL query. The ceil() function rounds the result up to the next integer.

    Once you have this result, you simply need to output links to each page, which can be done simply with a for loop:

    for($i = 0; i < $numPages; i++)
    {
        echo '<a href="/search.php?page="' . $i+1 . '>' . $i+1 . '</a>';
    }
    

    To create first, previous, next and last page links, you need to do something like:

    $firstPage = 1;
    $previousPage = $currentPage - 1; // you may want to check here or elsewhere to make sure you have no page zero
    $nextPage = $currentPage + 1; // may also want to make sure you don't go past the last page
    $lastPage = $numPages;
    

    These values can then be put into your generated links.

    Again, I will refer you to Luc M’s comment… These need to be fixed, take a look at mysqli functions instead of the now-deprecated mysql_*() functions you’re currently using, make sure you clean any user-inputted data before using it, and consider looking at the MVC design pattern.

    Hopefully, this will help you out.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.