PHP generated JSON paging problem
Recently in the generation of PHP generated JSON, want to implement paging, the code below has been able to create the array, paging how to implement it? Want to achieve every 10 pages of the page
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 < 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
Share to:
------Solution--------------------
You can split the page first and then generate the JSON.
------Solution--------------------
Mister, and then use Json_encode () to generate JSON.
------Solution--------------------
Paging is not in the client with JS, paging is usually on the server side with PHP to calculate the number of database required to obtain, and then directly from the database to obtain the selected records.
For example, you guide the page by the Get or post method,
$page = 1;//First page
$pagenum = 10;//per page
$start = ($page-1) * $PAGENUM;//This is the number of records that are calculated for the start
Your SQL statements can be written like this.
$sql = "SELECT * from AKB ORDER BY infoid desc LIMIT $start, $pagenum";
------Solution--------------------
The front-end part, for example with the jquery library