标签:mysqli list enc get host 查询 access start 字段
<?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); ?>
标签:mysqli list enc get host 查询 access start 字段
原文地址:https://www.cnblogs.com/zbl3033/p/13363809.html