2013-03-19 194 views
0

我正在使用我的網站上的搜索功能,並正在執行下一個和上一個功能,每頁顯​​示16個結果。我必須檢查,如果我的查詢不是null或一個空字符串,但我不擅長if語句,我猜我必須做一個嗎?我將AJAX用於下一個和上一個的點擊功能,但是在PHP中進行所有計算。我想這樣做的第一個查詢,我不得不使用一個if語句?這是我到目前爲止..我不知道哪個查詢來檢查是空的還是一個空字符串。檢查查詢是否爲空或空字符串

這是我工作的功能。我期待創建一個if語句來檢查查詢是不是null,但不確定如何?任何幫助將不勝感激:

public function keywordAction() { 
     $this->view->layout()->disableLayout(); 
     $this->_helper->viewRenderer->setNoRender(TRUE); 
     $session = new Zend_Session_Namespace("keyword"); 
     $search = ""; 
     if(isset($session->search)) { 
      $search = $session->search; 
     } 
     if { 


     } 
    } 

這是Ajax代碼我有一個功能:

$(".paginator").click(function(){ 
     var action = $(this).attr("action"); 
     var page = $("#pageNo").val(); 
     var pageint = parseInt(page); 
     var request = $.ajax({ 
      url : "/support/keyword/", 
      dataType : "JSON", 
      type : "POST", 
      data : { 
       action : action, 
       page : pageint, 
       itemsperpage : parseInt($("#itemsperpage").val()) 
      } 
     }); 

     request.done(function(response){ 
      if(response.error != undefined) { 
       window.location = "/"; 
      } 
      if(response.results != undefined) { 
       $("#output").html(response.results); 
      } 
      if(response.disable != undefined) { 
       if(/1/i.test(response.disable)) { 
        $(this).hide(); 
       } 
      } 
      if(response.undisable != undefined) { 
       if(/1/i.test(response.undisable)) { 
        if(/next/i.test(action)) { 
         $("#previous").show(); 
        } else { 
         $("#next").show(); 
        } 
       } 
      } 
      if(response.resultsstring != undefined) { 
       $("#resultsstring").html(response.resultsstring); 
      } 
     }); 

    }); 

回答

0

嘗試像

<?php 
    if(!empty($search)) { 

    } 
?> 
+0

謝謝..問題解決了! :-) – ash 2013-03-20 10:06:53