##1. 分頁原理:sql
limit offset, size offset:偏移量 offset=(當前頁-1)*size size:每頁顯示條數
order by ‘排序字段’ ‘正序或反序'
$doctor=M('freegoods'); $num=I('page','1','intval');//當前頁碼 $pagesize=I('size','5','intval');//每頁顯示條數 $count=$doctor->count();//總條數 $sort=I('sort','id');//當 $order=I('order','asc'); $totalpage = ceil($count/$pagesize);//總頁數 $offset = ($num-1)*$pagesize; $sql = "select id,doctorname,post,asktime,skill,storecode,gender,userimg from hx_doctor order by $sort $order limit $offset,$pagesize "; $info=$doctor->query($sql);