<?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 >= "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
}
}
?>
我的问题是如何使用会话在下一页重复查询。即如果页面超过1页的结果,我想存储查询。基本上市。我无法弄清楚存储查询的逻辑,并检查第一次加载页面的条件或是否继续搜索结果。
抱歉格式不正确。
答案 0 :(得分:0)
嗯,ASP为每个页面定义了属性IsPostBack,它回答了你之前是否已加载页面的问题。您可以通过创建存储在$ _SESSION ['bl']中的自定义商务类实例来使用相同的技术,并检查$ _SESSION ['bl']是否为空。在该类中,您可以定义存储查询和其他所需参数的属性。然后,您将获得所需的所有信息,并可以从那里开始