help with this code
<?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" ';
开发者_JAVA技巧 $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 >= "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->getSearchListings($tmpquery,$offset,$rowsPerPage);
for($i=0;$i<sizeof($listings[0]);$i++) {
if($i%2==0)
echo '<tr class="oddrow">';
else
echo '<tr>';
?>
<td class="colimage">
<?php if($listings[0][$i][0]=="") {?>
<a href="#"><img src="images/no-image.png" alt="no image" /></a>
<?php } else {?>
<a href="#"><img src="<?php echo $listings[0][$i][0]; ?>" alt="<?php echo $featured[0][$i][1]; ?>" /></a><?php }?>
</td>
<td class="coltitle"><?php echo $listings[0][$i][1]; ?></td>
<td class="colpurpose"><?php echo $listings[0][$i][2]; ?></td>
<td class="coltype"><?php echo $listings[0][$i][3]; ?></td>
<td class="colcity"><?php echo $listings[0][$i][4]; ?></td>
</tr>
<?php } ?>
</table>
<?php
//echo $getSearchRowsQuery;
if(!isset($_SESSION['searchcount']))
$numrows = $classObject->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 <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?page=$page\">$page</a> ";
$_SESSION['searchquery'] = $query;
$_SESSION['searchcount'] = $numrows;
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
}
?>
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.
sorry for improper formatting.
Well, ASP defines property IsPostBack for every page which answers your question whether page has been loaded before. You can use same technique by creating custom bussiness class instance of which you store in $_SESSION['bl'] and check if $_SESSION['bl'] is null. In that class you could define properties that store your query and other desired parameters. Then you'll have all information you need and can go from there
精彩评论