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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:00:56+00:00 2026-05-13T12:00:56+00:00

I am trying to implement paging and i done that. The problem is when

  • 0

I am trying to implement paging and i done that. The problem is when I click the search button the search results are displayed
with no problem.

1st Snap
http://www.flickr.com/photos/41695354@N08/4057149857/

2nd snap
http://www.flickr.com/photos/41695354@N08/4057149861/

When i click the next button, it once again gets the value from all the textboxes which is empty by default and sets the query as
select * from rentals_ads where city=”” which is 0 result, and so it displaying ‘No Results Found’.

3rd snap
http://www.flickr.com/photos/41695354@N08/4057149863/

How can i make the query string to form only at the time of clicking the search button??.

Any help will be highly appreciated.

My code:

rentals_search.template.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="../css/style.css"> </link>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RBlog - For the Consumers - By the Sellers</title>



<link href="css/Pager.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
    <script src="js/jquery.pager.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">

        $(document).ready(function() {
            $("#pager").pager({ pagenumber: 1, pagecount: 15, buttonClickCallback: PageClick });
        });

        PageClick = function(pageclickednumber) {
            $("#pager").pager({ pagenumber: pageclickednumber, pagecount: 10, buttonClickCallback: PageClick });
            //$("#result").html("Clicked Page " + pageclickednumber);
            $("#result").html("Clicked Page " + pageclickednumber);



        }
        gen();

    </script>





</head>

<body>
    <?php include("includes/header.php"); ?>
    <?php include("dbclass/paging_class.php"); ?>
    <div class="afterpicer_total">
        <?php include("includes/menu.php"); ?>
    <div class="wrapper">
            <div class="cont">
                <?php include("includes/left_menu.php"); ?>
                <div class="reg_cont">
                    <form action="search_results.php" method="GET">
                        <div class="reg_label">Looking for</div>
                        <div class="reg_tbox">
                            <select name="type" class="reg_combo_style">
                                <option>Living House</option>
                                <option>Office</option>
                            </select>
                        </div><br/>
                        <div class="reg_label">Rent/Month</div>
                        <div class="reg_tbox">
                            <select name="rent" class="reg_combo_style">
                                <option></option>
                                <option><2000</option>
                                <option>2000-4000</option>
                                <option>4000-6000</option>
                                <option>6000-10000</option>
                                <option>>10000</option>
                            </select>
                        </div><br/>
                        <div class="reg_label" >City</div>

                        <div class="reg_tbox">
                            <select name="city" class="reg_combo_style" >
                                <option></option>
                                <option>Chennai</option>
                                <option>Salem</option>
                                <option>Madurai</option>
                                <option>Trichy</option>
                            </select>
                        </div><br/>
                        <div class="reg_label" >Area</div>
                        <div class="reg_tbox"><input type="text" size="32" name="area" class="reg_tbox_style" value='<?php echo(htmlspecialchars($_SESSION["lastarea"], ENT_QUOTES)); ?>' ></input></div><br/><br/><br/>



                        <div class="reg_tbox"><input type="submit" name="subm" value="Search" class="reg_but_style"style="margin-left:155px;"></input></div><br/><br/>
                        <?php


                            //doPages(10, '/rentals_search.php', 'city=Madurai', 5);
                               /*if (isset($_GET['subm'])) {
                                     $_SESSION['searchflag'] = 'on';
                                    }

                                    if(isset($_SESSION['searchflag']))
                                    {
                                     $newpage=new paging();
                                    //$newpage->pager(" SELECT * FROM rentals_ads WHERE city='Salem'");
                                    $type=$_GET[type];
                                    $city=$_GET[city];
                                    $newpage->pager("SELECT * FROM rentals_ads WHERE city='$city'");
                                    }  */


                        ?>
                        <div class="reg_bl"></div>
                 </form>
             </div>
         </div>
         <div class="adspace"> Advertisement Space</div>
     </div>
</div>

<script language="javascript">
function gen()
{
for (var page = 0; page <= 10; page++) {
    var currentButton = $('<li class="page-number">' + (page) + '</li>');
    <a class="pager" href="/ajax_pages/get_results.php?page=3">page </a>

      }
      }


</script>
</body>
</html>

paging_class.php

<?php
ob_start();


    require_once("common/class.Database.php");
    require_once("common/varDeclare.php");

class paging extends Database
{
   function pager()
   {



        $no_results = TRUE;   // No results found yet
        $howmany    = 5;     // Return 10 results per query

        // Set default starting point of query to 0, or, if set, to $_GET['rs']
        $row_start  = (isset($_GET['rs'])) ? $_GET['rs'] : 0;


        // Do our SQL query, with something like LIMIT 0, 10

        $qcity=$_GET[city];
        $sql="SELECT * FROM rentals_ads WHERE city='$qcity'";
        $result=mysql_query($sql);
        while($row = mysql_fetch_array($result))
        {
             $count=$count+1;
        }
        if($count>0)
        {
        echo "$count results found" ;
        }



        $sql    = "SELECT * FROM rentals_ads WHERE city='$qcity' LIMIT ". $row_start .", ". $howmany ."";


        $result = mysql_query($sql);



        // Get the number of rows that would have been returned WITHOUT a limit clause, to be used later for paging.
        $count_sql        = "SELECT FOUND_ROWS() AS total";
        $count_sql_result = mysql_query($count_sql);

        $count_row    = mysql_fetch_array($count_sql_result);

        $count_result     = $count_row['total'];

        ?>
    <div class="paging_title">
        <div class="paging_title_title"> Title</div>
        <div class="paging_title_type">Room Type</div>
        <div class="paging_title_city">City</div>
        <div class="paging_title_rent">Rent</div>
    </div>
       <?
                // Start looping through our result set

        while($row = mysql_fetch_array($result)) {
            $no_results = FALSE;

            // Save results of query to $line_output
            $line_output .= "
                <div class=\"paging_ad\">
                    <div class=\"paging_ad_title\">". $row['rentals_title'] ."</div>
                    <div class=\"paging_ad_type\">". $row['rentals_type'] ."</div>
                    <div class=\"paging_ad_city\">". $row['city'] ."</div>
                    <div class=\"paging_ad_rent\">". $row['rent'] ."</div>
                </div>";
        }

        // Don't bother building paging if we don't have records
        if ($no_results) {
            $line_output = "No records found...";
            $page_output = "";
        }
        else {
            // Build <prev> and <next> links and save to $page_output
            $rs_prev = $row_start - $howmany; // where would prev page start, given current start less no. of records
            $rs_next = $row_start + $howmany; // where would next page start, given current start plus no. of records

            // If for some reason the next <prev> starting point is negative, do not display <prev>
            // This happens when our current starting point is already 0
            // This may happen if some smartass manually changes the rs= bit in the url
            $page_output_prev   = ($rs_prev < 0) ? "" : "<a href='?rs=".$rs_prev."'>Previous</a>";

            // Will the next page jump start point exceed the number of records returned?
            // If so, don't display <next>'
            $page_output_next   = ($rs_next <= $count_result) ?  "<a href='?rs=".$rs_next."'>Next</a>": "";

            // Just something to put between <prev> & <next>, IF they are both active
            if (($page_output_prev == ""))
            {
                 $page_output ="       <div class=\"paging_nav_cont\">


                    <div class=\"paging_nav_but\">". $page_output_next ."</div>
                    </div>";

            }
           else if (($page_output_next == ""))
            {
                $page_output ="       <div class=\"paging_nav_cont\">
                    <div class=\"paging_nav_but\">". $page_output_prev ."</div>


                    </div>";
            }

            else
            {
                $page_output ="       <div class=\"paging_nav_cont\">
                    <div class=\"paging_nav_but\">". $page_output_prev ."</div>

                    <div class=\"paging_nav_but\">". $page_output_next ."</div>
                    </div>";
            }
            // Build final paging output

            //$page_output = $page_output_prev . $page_output_breaker . $page_output_next;





        }

        // Write the outputs
        echo $line_output;
        echo $page_output;
   }
}
?>

search_results.template.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RBlog - For the Consumers - By the Sellers</title>
<?
require_once("common/class.Database.php");
require_once("dbclass/paging_class.php");
?>
</head>
<body>
    <?php include("includes/header.php"); ?>
    <div class="afterpicer_total">
        <?php include("includes/menu.php"); ?>
    <div class="wrapper">
            <div class="cont">

                <?
                                    $newpage=new paging();
                                    //$newpage->pager(" SELECT * FROM rentals_ads WHERE city='Salem'");
                                    $type=$_GET[type];
                                    $city=$_GET[city];
                                    $newpage->pager();
               ?>
            </div>
            <div class="adspace"> Advertisement Space</div>
       </div>
    </div>

</body>
</html>
  • 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-05-13T12:00:56+00:00Added an answer on May 13, 2026 at 12:00 pm

    No, Scavenger is right, you have to use the $_SESSION variable. It is the only way to make PHP remember things from the previous page load.

    The reason it was not working for you is probably because you haven’t set it up correctly. You have to add

    <?php session_start(); ?>
    

    to the beginning of each PHP file in which you want to use the $_SESSION variable. Then, you have to code something like:

    if (isset($_GET['city']) {
        $qcity = $_GET['city'];
        $_SESSION['city'] = $qcity;
    } else {
        $qcity = $_SESSION['city'];
    }
    

    to make it remember the city from last time.

    This is one way to tackle the problem, I think you could also solve the problem with AJAX. If you do that, you have to make sure that the page is never reloaded completely. This keeps the input fields valid. Instead of reloading, you call your PHP files (containing database queries) from Javascript, and manipulate the page accordingly.

    I’d go for PHP sessions (but I’m dying to learn more AJAX too, it’s neat :-).

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

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.