zoukankan      html  css  js  c++  java
  • php处理分页数据并返回json

    <?php
    header('content-type:application/json;charset=utf-8');//设置浏览器解析格式为json
    header('Access-Control-Allow-Origin: *');
    $curPage = $_GET['page'];//前台传递的当前页
    $pageSize = 20;//页容量大小
    $start = ($curPage - 1) * $pageSize;//起始页数
    $totalPage = 0;//总页数
    $conn = mysqli_connect("localhost", "root", "root","s");//数据库连接参数
    $pageList = array();//用来封装分页数据的数组
    	
    //执行分页查询的同时在数据库中设置一个新字段,总记录数
    $sql="SELECT * ,(select count(*) FROM s) as total from s limit $start,$pageSize";
    $result = mysqli_query($conn, $sql);
    	
    while ($row = mysqli_fetch_assoc($result)) {
    	$items = array(
    		"itemid" => $row['itemid'],
    		"itemtitle" => $row['itemtitle'],
    	    "image" => $row['itempic'],
    	    "price" => $row['orderfee']//
    	    );
    	    //总页数等于总记录数/页容量,向上取整, 如3.5页,要有第四页
    	    $totalPage = ceil($row['total'] / $pageSize);
    	    array_push($pageList, $items);//填充分页数据
    	}
    mysqli_close($conn);//关闭连接
    echo json_encode($pageList,JSON_UNESCAPED_UNICODE);
    ?>
    

      

  • 相关阅读:
    VS工作目录,输出目录
    Google的C++开源代码项
    C++文件读写
    深拷贝浅拷贝
    Efficient Graph-Based Image Segmentation
    Graph Cut 简介
    Graph Cut
    "GrabCut" - Interactive Foreground Extraction using Iter
    EM算法
    Python图像处理库(2)
  • 原文地址:https://www.cnblogs.com/zbl3033/p/13363809.html
Copyright © 2011-2022 走看看