help with this code
<pre><code>&lt;?php
      if(isset($_REQUEST['searchcat']))
  {
        $search_category = $_REQUEST['searchcat'];
        switch($search_category)
        {
            case 'Purchase':
                $city      = mysql_real_escape_string($_REQUEST['city']);
                $location  = mysql_real_escape_string($_REQUEST['location']);
                $bedrooms  = mysql_real_escape_string($_REQUEST['noofbedrooms']);
                $addeddate = mysql_real_escape_string($_REQUEST['addeddate']);
                $minprice  = mysql_real_escape_string($_REQUEST['pricefrom']);
                $maxprice  = mysql_real_escape_string($_REQUEST['priceto']);
                $minarea   = mysql_real_escape_string($_REQUEST['areafrom']);
                $maxarea   = mysql_real_escape_string($_REQUEST['areato']);
                $proptype   = mysql_real_escape_string($_REQUEST['proptype']);
                $addeddate = date($addeddate * 24 * 60 * 60);
                $query = 'SELECT image,propertytitle,propertypurpose,propertytype,city,id FROM properties WHERE 1 = 1 AND propertypurpose = "Purchase" ';
                $query .= strlen($city)     ? ' AND city = "'.$city.'"'         : '';
                $query .= strlen($location) ? ' AND location = "'.$location.'"' : '';
                $query .= strlen($bedrooms) ? ' AND bedrooms = "'.$bedrooms.'"' : '';
                if($addeddate!=0)
                    $query .= strlen($addeddate) ? ' AND dateadded &gt;= "FROM_UNIXTIME('.$addeddate.')"' : '';
                $query .= strlen($minprice) ? ' AND price between "'.$minprice.'"' : '';
                $query .= strlen($maxprice) ? ' AND "'.$maxprice.'"' : '';
                $query .= strlen($minarea) ? ' AND landarea between "'.$minarea.'"' : '';
                $query .= strlen($maxarea) ? ' AND "'.$maxarea.'"' : '';
                $query .= strlen($proptype) ? ' AND propertytype = "'.$proptype.'"' : '';
                $getSearchRowsQuery = explode('properties',$query);
                $getSearchRowsQuery = 'SELECT COUNT(id) As numrows FROM properties' . $getSearchRowsQuery[1];
                break;
            case 'rentals':
                break;
            case 'agents':
                break;
            case 'developments':
                break;
            default:
        }
    }
    $classObject = new class_functions();
    $rowsPerPage = 2;
    // by default we show first page
    $pageNum = 1;
    // if $_GET['page'] defined, use it as page number
    if(isset($_GET['page']))
    {
        $pageNum = $_GET['page'];
    }
    // counting the offset
    $offset = ($pageNum - 1) * $rowsPerPage;
    if(!isset($_REQUEST['searchcat']))
    {
        if(!isset($_REQUEST['page']))
        {
            $query = '';
            session_destroy($_SESSION['searchquery']);
            session_destroy($_SESSION['searchcount']);
        }
        else 
            $query = $_SESSION['searchquery'];
    }
else 
{
    session_destroy($_SESSION['searchquery']);
    session_destroy($_SESSION['searchcount']);
}
if(isset($_SESSION['searchquery']))
    $query = $_SESSION['searchquery'];
$tmpquery = $query . ' LIMIT ' . $offset . ', ' .$rowsPerPage;
echo $tmpquery;
$listings[] = $classObject-&gt;getSearchListings($tmpquery,$offset,$rowsPerPage);
for($i=0;$i&lt;sizeof($listings[0]);$i++) {
    if($i%2==0)
        echo '&lt;tr class="oddrow"&gt;';
    else
        echo '&lt;tr&gt;';
?&gt;
    &lt;td class="colimage"&gt;
            &lt;?php if($listings[0][$i][0]=="") {?&gt;
            &lt;a href="#"&gt;&lt;img src="images/no-image.png" alt="no image" /&gt;&lt;/a&gt;
                            &lt;?php } else {?&gt;
                                &lt;a href="#"&gt;&lt;img src="&lt;?php echo $listings[0][$i][0]; ?&gt;" alt="&lt;?php echo $featured[0][$i][1]; ?&gt;" /&gt;&lt;/a&gt;&lt;?php }?&gt;
                        &lt;/td&gt;
                        &lt;td class="coltitle"&gt;&lt;?php echo $listings[0][$i][1]; ?&gt;&lt;/td&gt;
                        &lt;td class="colpurpose"&gt;&lt;?php echo $listings[0][$i][2]; ?&gt;&lt;/td&gt;
                        &lt;td class="coltype"&gt;&lt;?php echo $listings[0][$i][3]; ?&gt;&lt;/td&gt;
                        &lt;td class="colcity"&gt;&lt;?php echo $listings[0][$i][4]; ?&gt;&lt;/td&gt;
                    &lt;/tr&gt;

                    &lt;?php } ?&gt;
                 &lt;/table&gt;
                    &lt;?php
                        //echo $getSearchRowsQuery;
                        if(!isset($_SESSION['searchcount']))
                            $numrows = $classObject-&gt;get_search_rows($getSearchRowsQuery);
                        else 
                            $numrows = $_SESSION['searchcount'];
                        if($numrows==0)
                        {
                            echo 'No records found.';
                        }
                        else 
                        {
                            // how many pages we have when using paging?
                            $maxPage = ceil($numrows/$rowsPerPage);

                            // print the link to access each page
                            $self = $_SERVER['PHP_SELF'];
                            $nav  = '';

                            for($page = 1; $page &lt;= $maxPage; $page++)
                            {
                               if ($page == $pageNum)
                               {
                                  $nav .= " $page "; // no need to create a link to current page
                               }
                               else
                               {
                                  $nav .= " &lt;a href=\"$self?page=$page\"&gt;$page&lt;/a&gt; ";
                                  $_SESSION['searchquery'] = $query;
                                  $_SESSION['searchcount'] = $numrows;
                               }
                            }
                            if ($pageNum &gt; 1)
                            {
                               $page  = $pageNum - 1;
                               $prev  = " &lt;a href=\"$self?page=$page\"&gt;[Prev]&lt;/a&gt; ";

                               $first = " &lt;a href=\"$self?page=1\"&gt;[First Page]&lt;/a&gt; ";
                            }
                            else
                            {
                               $prev  = '&amp;nbsp;'; // we're on page one, don't print previous link
                               $first = '&amp;nbsp;'; // nor the first page link
                            }

                            if ($pageNum &lt; $maxPage)
                            {
                               $page = $pageNum + 1;
                               $next = " &lt;a href=\"$self?page=$page\"&gt;[Next]&lt;/a&gt; ";

                               $last = " &lt;a href=\"$self?page=$maxPage\"&gt;[Last Page]&lt;/a&gt; ";
                            }
                            else
                            {
                               $next = '&amp;nbsp;'; // we're on the last page, don't print next link
                               $last = '&amp;nbsp;'; // nor the last page link
                            }
                        }
                    ?&gt;
</code></pre>

<p>My question is that how can i repeat the query on next pages using sessions. i.e i want to store the query if the pages exceeds results from 1 page. basically listing. I cant figure out the logic for storing the query and check for condition that the page is loaded first time or it is continuing search result.</p>

<p>sorry for improper formatting.</p>
