欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

请教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

网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论
  • 请教PHP生成JSON分页有关问题
  • 专题推荐

    作者信息
    请教PHP生成JSON分页有关问题

    认证0级讲师

    推荐视频教程
  • 请教PHP生成JSON分页有关问题javascript初级视频教程
  • 请教PHP生成JSON分页有关问题jquery 基础视频教程
  • 视频教程分类