Home  >  Q&A  >  body text

How to use the search function in thinkPHP3.2.3

thinkHow to use the search function in PHP3.2.3? What is wrong with the following

public function index(){
$article=D('article');
$keyboard=isset($_GET['keyboard'])?$_GET ['keyboard']:'';
$where=[]; //Search conditions
if($keyboard){ //Determine whether it is empty
$where['keyboard']=[' like',"%$keyboard%"];
}
$count= $article->where($where)->count();// Query the total number of records that meet the requirements
$Page = new \Think\Page($count,5);// Instantiate the paging class and pass in the total number of records and the number of records displayed on each page (25)
$show = $Page->show() ;//Page display output
$list = $article->where($where)->order('time desc')->limit($Page->firstRow.','.$Page ->listRows)->select();
$this->assign('list',$list);// Assignment data set
$this->assign('page',$ show);// Assignment paging output
$this->display();


meimeimeimei2342 days ago1133

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2018-04-24 20:39:16

    Print the SQL statement and then execute the SQL statement in the database to test and you will know the result

    reply
    0
  • 学乎者也

    学乎者也2018-04-23 23:14:45

    First make sure whether there is a keyboard field in your data. I think there should be no one.

    reply
    1
  • meimei

    Yes, the name of the input in the form = "keyboard", isn't it like this?

    meimei · 2018-04-23 23:23:16
  • Cancelreply