首页 > 代码库 > TP3.23 与Laypage 结合进行分页 增删改查

TP3.23 与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="http://www.mamicode.com/__PUBLIC__/jquery-1.11.1/jquery.min.js"></script>
	<script type="text/javascript" src="http://www.mamicode.com/__PUBLIC__/jquery-1.11.1/jquery.js"></script>
	<script type="text/javascript" src="http://www.mamicode.com/__PUBLIC__/layer/layer.js"></script>
	<script type="text/javascript" src="http://www.mamicode.com/__PUBLIC__/laypage/laypage.js"></script>
</head>
<body>
<div>
 <select name="" id="slc1" onchange="return choose()">
 	<option value="http://www.mamicode.com/-6" <if condition="$choose eq -6 "> selected </if> >全部</option>
 	<option value="http://www.mamicode.com/0"  <if condition="$choose eq 0 "> selected </if> >简单</option>
 	<option value="http://www.mamicode.com/1"  <if condition="$choose eq 1 "> selected </if> >一般</option>
 </select>
	<input type="text" value="http://www.mamicode.com/

  

TP3.23 与Laypage 结合进行分页 增删改查