2010-12-23 123 views
0
<?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 = '&nbsp;'; // we're on page one, don't print previous link 
           $first = '&nbsp;'; // 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 = '&nbsp;'; // we're on the last page, don't print next link 
           $last = '&nbsp;'; // nor the last page link 
          } 
         } 
        ?> 

我的問題是,如何重複使用會話的下一頁上的查詢。即如果頁面超過1頁的結果,我想存儲查詢。基本上市。我無法弄清楚存儲查詢的邏輯,並檢查頁面首次加載或繼續搜索結果的條件。幫助使用此代碼

抱歉格式不正確。

+0

次要代碼建議:創建'城市','位置'等數組,然後遍歷數組以調用'mysql_real_escape_string()'。 – Oli 2010-12-23 11:27:12

回答

0

那麼,ASP定義屬性IsPostBack爲每個頁面,回答你的問題是否頁面已被加載之前。您可以通過創建存儲在$ _SESSION ['bl']中的自定義商業類實例來使用相同的技術,並檢查$ _SESSION ['bl']是否爲空。在該類中,您可以定義存儲查詢和其他所需參數的屬性。然後你會得到所有你需要的信息,並且可以從那裏開始