• thinkphp分页二,分装到funciton.php


    function.php代码

    <?php
    /* 全局分页
     * $table                数据表名
     * $order                排序
     * $pagesize             每页显示N个
     * $where                查询条件
     * $rollPpage            控制分页 循环显示个数
     */
    function getpage($table,$pagesize,$order,$where='',$rollPpage='10'){
        $m = M($table);
        $count      = $m->where($where)->count();// 查询满足要求的总记录数
        $page       = new ThinkPage($count,$pagesize);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $page->listRows = $pagesize;
        $page->rollPage = $rollPpage;
        
        $show       = $page->show();// 分页显示输出
        $list = $m->where($where)->order($order)->limit($page->firstRow.','.$page->listRows)->select();
        
        $pages['list'] = $list;
        $pages['show'] = $show;
        return $pages;
    }

    php引用代码

    if(IS_POST){
                $files['depot_id'] = I('post.depot_id')    ;
                $files['keywords'] = I('post.keywords')    ;
            }
            
            if($files['depot_id']){
                $where['depot_id'] = $files['depot_id'];    
            }
            if($files['keywords']){
                $where['_string'] = ' (goods_name like "%'.$files['keywords'].'%")  OR ( goods_barcode like "%'.$files['keywords'].'") ';
            }
            $this->assign('files',$files);
            
            $table = 'stock_log';
            $pagesize = '10';
            $order = 'id desc';
            $pages = getpage($table,$pagesize,$order,$where);
            //格式化数据
            foreach($pages['list'] as $k=>$v){
                $pages['list'][$k]['local_add_time'] = date('Y-m-d H:i:s',$v['add_time']);    
            }
  • 相关阅读:
    .NET内存管理、垃圾回收
    C#容器类,性能介绍
    与LINQ有关的语言特性
    IMEI
    IMSI
    无源码调试smali
    IDA远程调试 在内存中dump Dex文件
    error C4996: 'scanf': This function or variable may be unsafe.
    vue 用axios实现调用接口下载excel
    读《JavaScript权威指南》笔记(三)--对象
  • 原文地址:https://www.cnblogs.com/wesky/p/5584950.html
Copyright © 2020-2023  润新知