Home>Article>Backend Development> think php5 multi-table query paging code method to get the total number

think php5 multi-table query paging code method to get the total number

William Shakespeare
William Shakespeare Original
2018-05-22 14:52:09 2334browse

I encounter a lot of paging situations in tp5. This article will explain the relevant knowledge.

Controller

$data = input('get.'); $info = []; //搜索条件 if(!empty($data['title'])){ $data['title'] = trim($data['title']); $info['topic_title'] = ['like','%'.$data['title'].'%']; } $list = BeModel::getList($info); $num = $list->total();//获取总数 return $this->fetch('',[ 'list' => $list, 'title' => empty($data['title']) ? '' :$data['title'], 'num' => $num ]);

Inside the model

$search = []; $search['b.status'] = ['neq',-1]; if(!empty($data['topic_title']) ){ $search['b.topic_title'] = $data['topic_title']; } $res = self::alias('b')->join('subject s','s.id=b.subject_id','left') ->join('law l','l.id=b.law_id','left') ->field('b.*,s.subject,l.name') ->where($search) ->order('id asc') ->paginate(4,false,[ 'query' => request()->param(), ]); return $res;

This article explains the paging problem of tp5. For more related content, please pay attention to the php Chinese website.

Function analysis of commonly used functions in php

PHP The simplest implementation method for verifying logged in users (basic form user verification)

In PHP development, how to determine whether the previous script has finished running during scheduled execution?

The above is the detailed content of think php5 multi-table query paging code method to get the total number. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn