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

来源:互联网 发布:embedpano.js下载 编辑:程序博客网 时间:2024/05/16 01:49

一. 制作表格内容搜索 
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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  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');}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
原创粉丝点击