数据库是连接sql2008的;
$Model = new \Think\Model();
$count =M('bbc')->count();// 查询满足要求的总记录数
$Page = new \Extend\Page($count,8);// 实例化分页类 传入总记录数和每页显示的记录数
$sql = 'select a.*,b.*,c.*,d.* from xxx as a, cc as b,dd as c, ee as d where a.id=b.id and a.id=c.id and a.id=d.id and a.id=d.id order by a.id DESC limit'.$Page->firstRow.','.$Page->listRows;
$vo = $Model->query($sql);
$show = $Page->show();// 分页显示输出
$this->assign('model', $vo);
$this->assign('page',$show);
$this->display();
提示:limit附近有语法错误,sql2008不支持limit语句,百度了很多方法,都没实现,求助上面语句实现分页。。。
可以一下都查出来 然后使用 array_slice( array, start , length) 函数来拆分出分页的数据
$info = array_slice( $vo , ($page * $length - 1) , $length) ;
$info 就是分页后的内容了
http://www.cnblogs.com/suger/p/4024246.html
http://www.cnblogs.com/suger/p/4024246.html
/**
@return \Think\Page
*/
function getpage(&$m,$where,$pagesize=10){
$m1=clone $m;//浅复制一个模型
$count = $m->where($where)->count();//连惯操作后会对join等操作进行重置
$m=$m1;//为保持在为定的连惯操作,浅复制一个模型
$p=new Think\Page($count,$pagesize);
$p->lastSuffix=false;
$p->setConfig('header','
$p->parameter=I('get.');
$m->limit($p->firstRow,$p->listRows);
return $p;
}
调用分页方法
$m=M('products');
$p=getpage($m,$where,10);
$list=$m->field(true)->where($where)->order('id desc')->select();
$this->list=$list;
$this->page=$p->show();
view代码