请教PHP生成JSON分页有关问题
程序员文章站
2024-01-31 13:16:04
...
请问PHP生成JSON分页问题
最近在搞生成PHP 生成JSON,想实现分页,下边代码已能把数组生成了,分页要怎实现了?想实现每10条分一次页
//connection information
$host = "XXX";
$user = "XXX";
$password = "XX";
$database = "XX";
//make connection
$server = mysql_connect($host, $user, $password);
$connection = 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 $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 $json .= ",";
else
$json .= "]}";
}
$response = $_GET["callback"] . $json;
echo $response;
//close connection
mysql_close($server);
?>
最近在搞生成PHP 生成JSON,想实现分页,下边代码已能把数组生成了,分页要怎实现了?想实现每10条分一次页
//connection information
$host = "XXX";
$user = "XXX";
$password = "XX";
$database = "XX";
//make connection
$server = mysql_connect($host, $user, $password);
$connection = 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 $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 $json .= ",";
else
$json .= "]}";
}
$response = $_GET["callback"] . $json;
echo $response;
//close connection
mysql_close($server);
?>
php json
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
- 最新文章
- 热门排行
上一篇: php将地区分类排序的算法
下一篇: getimagesize里参数路径的问题
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论