php原生分页

php原生分页_第1张图片

total;
}
//分页数据
function data($sql){
    $link=con();
    $result  = mysqli_query($link,$sql); //获取所有的数据
    $arr=array();
    while($t_result = mysqli_fetch_array($result,MYSQLI_ASSOC)){
        $arr[]=$t_result;
    }
    mysqli_free_result($result);
    mysqli_close($link);
    return $arr;
}
function page($count,$listRows,$curPage,$rowsmaxPage =null,$search=null){
    $search = isset($search)?$search:"";
    $rowsmaxPage = isset($rowsmaxPage)?$rowsmaxPage:10;
    $totalpage =ceil($count/$listRows);
    //存储页码字符串
    $pageNumString = "";
    if($curPage <=($rowsmaxPage/2)){
        $begin =1;
        $end = $totalpage>=$rowsmaxPage?$rowsmaxPage:$totalpage;
    }else{
        $end = $curPage +($rowsmaxPage/2)>$totalpage?$totalpage:$curPage +($rowsmaxPage/2);
        $begin =$end -$rowsmaxPage-1<=1?1:$end -$rowsmaxPage-1;
    }
    //实现上一页
    $prev = $curPage -1<=1?1:$curPage -1;
    $pageNumString .="
  • ".$count." Record ".$curPage."/".$totalpage." PAGE

  • "; $pageNumString .="
  • 首页
  • "; $pageNumString .="
  • «
  • "; //根据起始页与终止页将当前页面的页码显示出来 for($i=$begin;$i<=$end;$i++){ //使用if实现高亮显示当前点击的页码 if($curPage == $i){ $pageNumString .= "
  • $i
  • "; }else{ $pageNumString .= "
  • $i
  • "; } } //实现下一页 $next = $curPage +1 >=$totalpage?$totalpage:$curPage +1; $pageNumString .="
  • »
  • "; $pageNumString .="
  • 尾页
  • "; $pageNumString .="
  •   GO
  • "; return $pageNumString; } //定义一个最大的页码数 $rowsmaxPage = 6; // 默认列表每页显示行数 $listRows = 10; //总记录数SQL isset($_REQUEST["search"])?($search= $_REQUEST["search"]):$search=""; $where = "1=1 "; $where .=" and concat_ws('',p.mCode,p.mDesc1,g.mPrice) like '%".trim($search)."%' "; $countsql = "SELECT count(*) as total FROM t_product as p LEFT JOIN t_product_pricegroup as g on p.T_Product_ID=g.T_Product_ID and g.mItem=1 where $where"; $count = taotalCount($countsql); //当前页 $curPage = isset($_GET['curPage'])?($_GET['curPage']>ceil($count/$listRows)?ceil($count/$listRows):$_GET['curPage']):1; //分页数据 $offset = ($curPage-1)*$listRows; $sql = "SELECT mCode,mDesc1,mPrice FROM t_product as p LEFT JOIN t_product_pricegroup as g on p.T_Product_ID=g.T_Product_ID and g.mItem=1 where $where limit $offset,$listRows"; $data = data($sql); //分页样式 $page = page($count,$listRows,$curPage,$rowsmaxPage,$search); ?> 食品维护
    search
    $vo ){?>

    你可能感兴趣的:(PHP,php原生分页,跳转指定页)