Home > Backend Development > PHP Tutorial > 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

jacklove
Release: 2023-03-27 12:56:02
Original
2426 people have browsed it

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
    ]);
Copy after login

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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template