duanfu4446 2013-03-19 11:18
浏览 92
已采纳

检查查询是否为空或空字符串

I am working on a search function on my website and i am onto doing a next and previous feature, displaying 16 results per page. I have to check if my query isnt null or an empty string however i am no good at if statements as such and i am guessing i have to do one? I am using AJAX for the click functions of next and previous but doing all the calculations in PHP. I guess to do this first query, i have to use an if statement? This is what i have so far.. I don't know which query to check for that is null or an empty string.

This is the function i am working on. I am looking to create an if statement to check if query isnt null but unsure how? Any help would be greatly appreciated:

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 {


        }
   }

This is the AJAX code i have for the function:

$(".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);
            }
        });

    });
  • 写回答

1条回答 默认 最新

  • dpeqsfx5186 2013-03-19 11:41
    关注

    Try something like

    <?php 
        if(!empty($search)) {
    
        }
     ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题