Think PHP 学习笔记 10.查询方式实例演示

一. 制作表格内容搜索
1.在模板的table上加form表单

<form action = '__URL__/search' method = 'post'>
    用户名:<input type="text" name="username">
    性别:
    男<input type="radio" name="sex" value="1">
    女<input type="radio" name="sex" value="0">
</from>
  1. 在模块search里, 写搜索的方法
public function search(){
    if(isset($_POST['username'])){
    $where['username']=array('like',"%$_POST['username']%");
    }
    if(iseet($_POST['sex'])){
        $where[
        'sex']=array('like',"%$_POST['sex']%")
    }
    //实例化数据库
    $m = M('User');
    $arr = $m->where($where)->select();
    $this->arr = $arr;
    $this->display('index');
}
posted @ 2022-12-06 22:23  轻风细雨_林木木  阅读(11)  评论(0编辑  收藏  举报