thinkPHP3.2.3結合Laypage實現分頁功能
这篇文章主要介绍了thinkPHP3.2.3结合Laypage实现的分页功能,结合实例形式分析了thinkPHP3.2.3结合Laypage实现分页的model控制器与view视图相关操作技巧,需要的朋友可以参考下
本文实例讲述了thinkPHP3.2.3结合Laypage实现的分页功能。分享给大家供大家参考,具体如下:
控制器
<?php namespace Home\Controller; use Think\Controller; class IndexController extends Controller { /** *@brief 查询 ****/ public function index(){ $choose = I('choose','-6'); $c['easy_hard'] = $choose; $type=I('typeid',''); $nowpage=I('page',1); if($type == '') { if($choose == -6) { $totalpage=ceil((D('data')->count())/10); $infos=D('data')->limit(($nowpage-1)*10,10)->select(); }else{ $totalpage=ceil((D('data')->where($c)->count())/10); $infos=D('data')->where($c)->limit(($nowpage-1)*10,10)->select(); } }else{ if($choose == -6) { $map['data'] = array('like',"%$type%"); $totalpage=ceil((D('data')->where($map)->count())/10); $infos=D('data')->where($map)->limit(($nowpage-1)*10,10)->select(); }else{ $map['data'] = array('like',"%$type%"); $totalpage=ceil((D('data')->where($map)->where($c)->count())/10); $infos=D('data')->where($map)->where($c)->limit(($nowpage-1)*10,10)->select(); } } $this->assign('type',$type); $this->assign('choose',$choose); $this->assign("totalpage",$totalpage); $this->assign("infos",$infos); $this -> display(); } }
视图层
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Think Demo</title> <script type="text/javascript" src="__PUBLIC__/jquery-1.11.1/jquery.min.js"></script> <script type="text/javascript" src="__PUBLIC__/jquery-1.11.1/jquery.js"></script> <script type="text/javascript" src="__PUBLIC__/layer/layer.js"></script> <script type="text/javascript" src="__PUBLIC__/laypage/laypage.js"></script> </head> <body> <p> <select name="" id="slc1" onchange="return choose()"> <option value="-6" <if condition="$choose eq -6 "> selected </if> >全部</option> <option value="0" <if condition="$choose eq 0 "> selected </if> >简单</option> <option value="1" <if condition="$choose eq 1 "> selected </if> >一般</option> </select> <input type="text" value="<if condition="$type neq '' "> {$type} </if>" id="type"><button id="sou">搜索</button> </p> <br> <table border="1" width="500" height="150" > <tr> <th>ID</th> <th>语言</th> <th>难易程度</th> <th>操作</th> </tr> <volist name="infos" id="vo"> <tr> <th>{$vo.id}</th> <th>{$vo.data}</th> <th> <if condition="$vo.easy_hard eq '0'">简单 <else />一般 </if> </th> <th> <a href="javascript:;" rel="external nofollow" rel="external nofollow" onclick="return del({$vo.id});">删除</a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" onclick="return edit({$vo.id});">修改</a> </th> </tr> </volist> </table> <p style="margin-top:15px; text-align:center;" id="page11"></p> <button onclick="return add_()"> 添加 </button> <br /> <script type="text/javascript"> function choose() { var type=$("#type").val(); var checkValue=$("#slc1").val(); window.location.href="?typeid=" rel="external nofollow" rel="external nofollow" +type+"&choose="+checkValue; } $("#sou").bind("click",function(event){ var type=$("#type").val();//获取假设的搜索条件值 var checkValue=$("#slc1").val(); window.location.href="?typeid=" rel="external nofollow" rel="external nofollow" +type+'&choose='+checkValue; }); $(function(){ laypage({ cont: 'page11', pages: {$totalpage}, //假设我们获取到的是18(后端计算完总页数后将总页数值传过来,放在这里即可(类似{$totalpage})). curr: function(){ //通过url获取当前页,也可以同上(pages)方式获取 var page = location.search.match(/page=(\d+)/); return page ? page[1] : 1;//如果没有页数显示时,默认是第一页 }(), jump: function(e, first){ //触发分页后的回调 if(!first){ //一定要加此判断,否则初始时会无限刷新 location.href=setParam("page",e.curr); } } }); }); function setParam(param,value){ var query = location.search.substring(1); var p = new RegExp("(^|)" + param + "=([^&]*)(|$)"); if(p.test(query)){ //query = query.replace(p,"$1="+value); var firstParam=query.split(param)[0]; var secondParam=query.split(param)[1]; if(secondParam.indexOf("&")>-1){ var lastPraam=secondParam.split("&")[1]; return '?'+firstParam+'&'+param+'='+value+'&'+lastPraam; }else{ if(firstParam){ return '?'+firstParam+''+param+'='+value; }else{ return '?'+param+'='+value; } } }else{ if(query == ''){ return '?'+param+'='+value; }else{ return '?'+query+'&'+param+'='+value; } } } </script> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
以上是thinkPHP3.2.3結合Laypage實現分頁功能的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PHP開發:如何實現表格資料排序和分頁功能在進行Web開發中,處理大量資料是一項常見的任務。對於需要展示大量資料的表格,通常需要實現資料排序和分頁功能,以提供良好的使用者體驗和最佳化系統效能。本文將介紹如何使用PHP實作表格資料的排序和分頁功能,並給出具體的程式碼範例。排序功能實作在表格中實作排序功能,可以讓使用者根據不同的欄位進行升序或降序排序。以下是一個實作表格

CakePHP是一個強大的PHP框架,為開發人員提供了許多有用的工具和功能。其中之一是分頁,它可以幫助我們將大量資料分成幾頁,從而簡化瀏覽和操作。預設情況下,CakePHP提供了一些基本的分頁方法,但有時你可能需要建立一些自訂的分頁方法。這篇文章將向您展示如何在CakePHP中建立自訂分頁。步驟1:建立自訂分頁類別首先,我們需要建立一個自訂分頁類別。這個

隨著數據的不斷增長,表格顯示變得更加困難。大多數情況下,表格中的資料量過大,導致表格在載入時變得緩慢,而且使用者需要不斷地瀏覽頁面才能找到自己想要的資料。本文將介紹如何使用JavaScript實作表格資料的分頁顯示,讓使用者更容易找到自己想要的資料。一、動態建立表格為了讓分頁功能更可控,需要動態建立表格。在HTML頁面中,新增一個類似下面的table元素。

如何使用JavaScript實作表格分頁功能?隨著網路的發展,越來越多的網站都會使用表格來展示數據。在某些資料量較大的情況下,需要將資料進行分頁展示,以提升使用者體驗。本文將介紹如何使用JavaScript實作表格分頁功能,並提供具體的程式碼範例。一、HTML結構首先,我們需要準備一個HTML結構來承載表格和分頁按鈕。我們可以使用<tab

MyBatis是一個優秀的持久層框架,它支援基於XML和註解的方式操作資料庫,簡單易用,同時也提供了豐富的插件機制。其中,分頁插件是使用頻率較高的插件之一。本文將深入探討MyBatis分頁外掛的原理,並結合具體的程式碼範例進行說明。一、分頁外掛原理MyBatis本身並沒有提供原生的分頁功能,但可以藉助外掛程式來實現分頁查詢。分頁插件的原理主要是透過攔截MyBatis

如何利用Layui開發一個具有分頁功能的資料展示頁面Layui是一個輕量級的前端UI框架,提供了簡潔美觀的介面元件和豐富的互動體驗。在開發中,我們經常會遇到需要展示大量資料並進行分頁的情況。以下是利用Layui開發的具有分頁功能的資料展示頁面的範例。首先,我們需要引入Layui的相關文件和依賴。在html頁面的<head>標籤中加入以下代

Vue元件實戰:分頁元件開發介紹在網路應用程式中,分頁功能是不可或缺的一個元件。一個好的分頁元件應該展示簡潔明了,功能豐富,而且易於整合和使用。在本文中,我們將介紹如何使用Vue.js框架來開發一個高度可自訂化的分頁元件。我們將透過程式碼範例來詳細說明如何使用Vue元件開發。技術堆疊Vue.js2.xJavaScript(ES6)HTML5和CSS3開發環

Vue是一種流行的JavaScript框架,用於建立使用者介面。在Vue技術開發中,實現分頁功能是常見的需求。本文將介紹如何使用Vue來實現分頁功能,並提供具體程式碼範例。在開始之前,我們需要提前準備一些基本知識。首先,我們需要了解Vue的基本概念和文法。其次,我們需要知道如何使用Vue元件來建立我們的應用程式。在開始之前,我們需要在Vue專案中安裝一個分頁插件,
