I have been generating PHP & nbsp; JSON pagination in PHP recently. to implement pagination, the following code can generate arrays. how can I implement pagination? I want to achieve every 10 pages per page & lt ;? Php & nbsp; // connection & nbsp; information may I ask questions about JSON paging generated by PHP?
Recently, PHP is being generated to generate JSON. to implement paging, the following code can generate arrays. how can we implement paging? To achieve every 10 pages
// 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 );
?>
Share php json:
------ Solution --------------------
You can pagination first and then generate json.
------ Solution --------------------
And then use json_encode () to generate json.
------ Solution --------------------
Pages are not divided by JS on the client. pages are usually calculated on the server using PHP to obtain the number of database records and then the selected records are obtained directly from the database.
For example, you used the GET or POST method to guide the page number,
$ Page = 1; // page
$ Pagenum = 10; // number of entries per page
$ Start = ($ page-1) * $ pagenum; // This is the number of records starting from calculation.
// Your SQL statement can be written in this way
$ SQL = "SELECT * FROM akb order by infoid desc LIMIT $ start, $ pagenum ";
------ Solution --------------------
Front-end, for example, using the jquery library