标准搜索案例

Posted jiqing9006

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了标准搜索案例相关的知识,希望对你有一定的参考价值。

html

<div class="alert sb-alert alert-gray margin-left-50">
    <div class="row">
    <div class="col-lg-2">
        <span class="input-group input-group-sm">
            <span class="input-group-addon"><b>姓名:</b></span>
            <input type="text" class="form-control" id="name" value="{$name}" aria-describedby="base">
        </span>
    </div>

    <div class="col-lg-2">
        <span class="input-group input-group-sm">
            <span class="input-group-addon"><b>手机号:</b></span>
            <input type="text" class="form-control" id="telphone" value="{$telphone}" aria-describedby="base">
        </span>
    </div>

    <div class="col-lg-2">
        <span class="input-group input-group-sm">
            <span class="input-group-addon"><b>状态:</b></span>
            <select id="status" class="form-control" style="position: relative; left:-4px;z-index: 1;" aria-describedby="object">
                <option value="0">请选择</option>
                <option value="-1" <?php if($status == -1) echo 'selected'; ?>>未处理</option>
                <option value="1" <?php if($status == 1) echo 'selected'; ?>>已发货</option>
                <option value="2" <?php if($status == 2) echo 'selected'; ?>>已丢弃</option>
            </select>
        </span>
    </div>


        <button type="button" class="btn btn-sm btn-primary" style="float: right; margin-right: 15px;" id="search">
            <i class="fa fa-search" aria-hidden="true"></i> 搜索
        </button>
    </div>

</div>

js

$("#search").on('click', function () {
    var pathname = window.location.pathname;

    var name = $("#name").val();
    var telphone = $("#telphone").val();
    var status = $("#status").val();

    var tail = '?search=1';

    if(name){
        tail += '&name='+name;
    }
    if(status){
        tail += '&status='+status;
    }

    if(telphone){
        tail += '&telphone='+telphone;
    }
    window.location.href = "http://" + window.location.host + pathname + tail;
});

php

// search
$where = [];
if ($name = $_GET['name']) {
    $where['name'] = ['like',$name.'%'];
    $this->assign('name',$name);
}

if ($telphone = $_GET['telphone']) {
    $where['telphone'] = ['like',$telphone.'%'];
    $this->assign('telphone',$telphone);
}

if ($status = $_GET['status']) {
    if ($status == -1) {
        $where['status'] = 0;
    } else {
        $where['status'] = $status;
    }
    $this->assign('status',$status);
}

$data_list=$women_get->where($where)->order('id desc')->limit($start.','.$step)->select();

干净利落

以上是关于标准搜索案例的主要内容,如果未能解决你的问题,请参考以下文章

Express实战 - 应用案例- realworld-API - 路由设计 - mongoose - 数据验证 - 密码加密 - 登录接口 - 身份认证 - token - 增删改查API(代码片段

如何在 BottomNavigationView 的片段上打开搜索界面?

在案例演示中嵌入片段

26个jQuery代码片段使用技巧

一个标准的单元UI自动化测试代码案例

VBA for Excel - 如果更深的选择案例不匹配标准,请再次避免输入代码