fastadmin对查询结果集进行分页

            //$arr = array();
            //if(!empty($arr)){
                //foreach ($arr as $key => $value) {
                    //foreach ($value['productList'] as $k => $v) {
                        //$list[] = $v;
                    //}
                //}
            //}
            $list = array();
            $page = ($_GET['offset']/10) + 1;
            $pagesize = $_GET['limit'];
            if($page == 1){
                $data = [];
                foreach ($list as $key => $value) {
                    if($key < $pagesize){
                        $data[] = $value;
                    }
                }
            }
            if($page > 1){
                $data = [];
                foreach ($list as $key => $value) {
                    if(($key >= (($page-1) * $pagesize)) && ($key <= (($page * $pagesize) - 1))){
                        $data[] = $value;
                    }
                }
            }
            return json(['total'=>count($list),'rows'=>$data]);

 

posted @ 2023-07-04 11:50  blog_zss小帅-博客猿  阅读(389)  评论(0编辑  收藏  举报