• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

请教PHP生成JSON分页有关问题

php 搞代码 4年前 (2022-01-24) 14次浏览 已收录 0个评论

请问PHP生成JSON分页问题
最近在搞生成PHP 生成JSON,想实现分页,下边代码已能把数组生成了,分页要怎实现了?想实现每10条分一次页
<?php

//connection information
$host = “XXX”;
$user = “XXX”;
$password = “XX”;
$database = “XX”;

//make connection
$server = mysql_connect($host, $user, $password);
$conne/本文来源gaodai#ma#com搞*!代#%^码网%搞代gaodaima码ction = mysql_select_db($database, $server);

//query the database
mysql_query(‘set character set “utf8″‘);
$query = mysql_query(“SELECT * FROM akb order by infoid desc”);

//start json object
$json = ‘{“tags”:[‘;

//loop through and return results
for ($x = 0; $x < mysql_num_rows($query); $x++) {
$row = mysql_fetch_assoc($query);
$infoid=$row[“InfoId”];
$Title=$row[“Title”];
$pic=$row[“LogoImg”];
$bpic=$row[“LogoImg2”];
$time=$row[“AccTime”];
$info=$row[“Burden”];
$url=$row[“ExtUrl”];

$json .= ‘{“id”:”‘. $infoid .'”,”title”:”‘.$Title.'”,”pic”:”‘.$pic.'”,”bpic”:”‘.$bpic.'”,”time”:”‘.$time.'”,”info”:”‘. $info .'”,”url”:”‘. $url.'”}’;

if ($x < mysql_num_rows($query) -1)
$json .= “,”;
else
$json .= “]}”;
}

$response = $_GET[“callback”] . $json;
echo $response;

//close connection
mysql_close($server);

?>

php json

发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址