1.$cid=empty($_GET['cid'])?16:$_GET['cid'];//判断传过来的cid,
$count=M('news')->where('category_id='.$cid)->count();查询这个分类下的长度
$page=new ThinkPage($count,6);//截取6条数据分页输出
$page->rollPage=4;
$page->setConfig('first','首页');//配置前端显示
$page->setConfig('prev','上一页');//配置前端显示
$page->setConfig('next','下一页');//配置前端显示
$show=$page->show();//
$list=M('news')->where('category_id='.$cid)->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();//页码生成和显示
$this->assign('data',$list);//定义
$this->assign('page',$show);//定义分页;
2.结算功能的实现
public function products(){
if(IS_POST){//判断用户有没有登录
if($_SESSION['vipname']==''){
$this->error('请先登录',U('Login/index'));
}else{
$pid=I('post.id');//post传过来的产品id
$num=I('post.num');//post传过来的数量
$data['ordernum']='dd'.time().rand(1000,9999);//生成订单号
$product=M('products')->where('id="'.$_POST['id'].'"')->find();//查询产品表的id
$data['pid']=$product['id'];
$data['pimg']=$product['image1'];
$data['name']=$product['name'];
$data['state']=0;
$data['price']=$product['price'];
$data['num']=I('post.num');
$data['vipid']=$_SESSION['vipname'];
$res=M('orders')->add($data);//将data的数据添加到order表里
if($res){
session('ordernum',$data['ordernum']);
$this->success('正在进入结算页面,请稍后......',U('Vipcenter/pay','or='.$data['ordernum']));
}else{
$this->success('参数错误,请重试');
} }
}else{
$cid=empty($_GET['cid'])?21:$_GET['cid'];
$count=M('products')->where('category_id='.$cid)->count();
$page=new ThinkPage($count,6);
$page->rollPage=4;
$page->setConfig('first','首页');
$page->setConfig('prev','上一页');
$page->setConfig('next','下一页');
$show=$page->show();
$list=M('products')->field('products.*,category.name as pname')->join('category on products.category_id=category.id')->where('category_id='.$cid)->order('products.id desc')->limit($page->firstRow.','.$page->listRows)->select();
$this->assign('data',$list);
$this->assign('page',$show);
$this->display('products');
}
}