• PHP 万能查询代码


    小项目中存在很多省市区加模糊查询:

    以下THINKPHP + JS 构成万能查询代码;方便快捷。

    前端:

    <select id="s_province" name="pro"></select>&nbsp;&nbsp;
    <select id="s_city" name="city" ></select>&nbsp;&nbsp;
    <select id="s_county" name="area"></select>&nbsp;&nbsp;
    <input type="text" style=" 200px" name = "search" id ="search" value ="{$search}" placeholder="地址综合会员名称搜索">
    <input type="button" value ="搜索" onclick = "search('/index.php?s=/Shendou/Member/mList')">
    <script class="resources library" src="__STATIC__/area.js" type="text/javascript"></script>
    <script type="text/javascript">_init_area();</script>
    
    <script>
    $pro = "<?php echo $pro ?>";
    $city = "<?php echo $city ?>";
    $area = "<?php echo $area ?>";
    if($pro != ""){
    update($pro,$city,$area);
    }
    </script>

    效果:

    JS 代码

    function search(basePath){
        var pro = $("#s_province").val();
        var city = $("#s_city").val();
        var area = $("#s_county").val();
        //obj 代表当前选哪个select框框
        var parm = "";
        var type = "";
        if(area != '市、县级市'){
            type = "area";
            parm = area;
        }else if(city != '地级市'){
            type = "city";
            parm = city;
        }else if(pro != '省份'){
            type = "pro";
            parm = pro;
        }
        var search =$("#search").val();
    
        window.location.href = basePath+"/type/"+type+"/parm/"+parm+"/search/"+search+"/pro/"+pro+"/city/"+city+"/area/"+area+".html";
    
    }

    bathPath: 主要是构造提交路径;

    后端代码:

    $wherestr = " AND 1 = 1 ";
    
    $type = $_REQUEST['type'];
    $parm = $_REQUEST['parm'];
    $search = $_REQUEST['search'];
    
    if($parm){
    $wherestr .= "AND `$type` = '$parm'";
    }
    
    if($search){
    $wherestr .= "AND `shopname` like '%$search%'";
    }
    
    $type = $_REQUEST['type'];
    $parm = $_REQUEST['parm'];
    $search = $_REQUEST['search'];
    
    if($parm){
    $wherestr .= "AND `$type` = '$parm'";
    }
    
    if($search){
    $wherestr .= "AND `shopname` like '%$search%'"; 
    }
    维护查询后选中

      $pro = $_REQUEST['pro'];
      $city = $_REQUEST['city'];
      $area = $_REQUEST['area'];
      $this->assign('pro',$pro);
      $this->assign('city',$city);
      $this->assign('area',$area);
      $this->assign('search',$search);

     
    积累知识,分享知识,学习知识。
  • 相关阅读:
    jquery sortable 在ie中拖动的后tabs不显示解决了
    光标是停在文本框文字的最后 ie
    PetShop安装
    Python小题目 针对快速教程
    vb升级到vb.net的一些文章(downmoon收集自msdn)
    [算法 笔记]大根堆
    [More Effective C++ 学习笔记]异常
    [More Effective C++ 学习笔记]效率
    [TCP IP详解:学习笔记]TCP定时器
    【Linux 编程】pthead_cond_t 的使用
  • 原文地址:https://www.cnblogs.com/bin-pureLife/p/4416212.html
Copyright © 2020-2023  润新知