Ask PHP to generate JSON paging related issues

Source: Internet
Author: User
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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.