Paging Homepage
<Meta http-equiv = "Content-Type" content = "text/html; charset = utf8"/>
<H1 align = "center"> pagination of martial arts novels <Br/>
<SCRIPT src = "jquery-1.4.2.min.js"> </SCRIPT>
<SCRIPT>
VaR page = '';
Function Init (PAGE ){
Document. getelementbyid ("tables"). innerhtml = '';
VaR xhr;
If (window. XMLHttpRequest ){
Xhr = new XMLHttpRequest ();
} Else if (window. activexobject ){
Xhr = new activexobject ("Microsoft. XMLHTTP ")
}
VaR url = "fenye. php ";
Xhr. Open ("Post", URL, true );
Xhr. onreadystatechange = callback;
Xhr. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
If (PAGE ){
Xhr. Send ("page =" + page );
}
Else {xhr. Send ("page = 1 ");}
VaR content;
Function callback (){
If (xhr. readystate = 4 ){
If (xhr. Status = 200 ){
VaR JSON = eval ('+ xhr. responsetext + ')');
// Alert (xhr. responsetext );
VaR fenye = JSON. STR;
// Alert (fenye );
Document. getelementbyid ('div '). innerhtml = fenye;
Content = "<TH> id </Th> <TH> name </Th> <TH> author </Th> <TH> press </Th> <TH> ISBN No. </Th> <TH> type </Th> <TH> price </Th> ";
For (VAR I = 0; I <json.info. length; I ++ ){
Content + = "<tr> <TD>" + json.info [I]. ID + "</TD> <TD>" + json.info [I]. name + "</TD> <TD>" + json.info [I]. author + "</TD> <TD>" + json.info [I]. publisher + "</TD> <TD>" + json.info [I]. ISBN + "</TD> <TD>" + json.info [I]. type + "</TD> <TD>" + json.info [I]. price + "</tr> ";
Document. getelementbyid ("tables"). innerhtml = content;
}
// Alert (fenye );
}
}
}
}
</SCRIPT>
<Body onload = "Init ()">
<H3 align = "center"> jquery implementation $. Ajax pagination <Table id = "tables" style = "width: 500px; Height: 100px; text-align: center "align =" center "border =" 5 "bordercolor =" # ff6600 ">
<TH> id </Th> <TH> name </Th> <TH> author </Th> <TH> press </Th> <TH> ISBN number </Th>> <TH> type </Th> <TH> price </Th>
</Table>
<Table align = "center" style = "margin-top: 15px">
<Tr> <TD>
<TD style = "colspan: 3; Height: 20">
<Div id = "Div" style = "position: absolute; left: 447px; top: 218px; width: 411px; Height: 22px;"> </div>
</TD>
</Tr>
</Table>
<Br/>
</Body>
Paging PHP essential code
<? PHP
// Process data at the command model layer
$ Link = mysql_connect ('localhost', 'root', '') or die (" failed ");
Mysql_select_db ('books ', $ link) or die ("An error occurred while connecting to the database! ");
// Number of records displayed per page
$ Pagesize = 2;
// Obtain the total number of records
$ SQL = "select count (*) as total_rows from books ";
$ Result = mysql_query ($ SQL );
$ Total_rows = mysql_fetch_array ($ result );
// Calculate the total number of page numbers
$ Pages = Ceil ($ total_rows [0]/$ pagesize );
// Current page
$ Page = $ _ post ['page'];
$ Strtext = "current section". $ page. "Page". "Total". $ pages. "Page". "Total". $ total_rows [0]. "record ";
// Var_dump ($ Str );
// Next, I will find the corresponding data based on the page number currently clicked
$ Offset = $ pagesize * ($ page-1 );
$ SQL = "select * From books limit $ offset, $ pagesize ";
Mysql_query ("set names utf8 ");
$ Res = mysql_query ($ SQL );
$ Rows = array ();
While ($ ROW = mysql_fetch_assoc ($ res )){
$ Rows [] = $ row;
}
$ Pageinfo = $ rows;
// Echo json_encode ($ pageinfo );
// Var_dump ($ pageinfo );
// Get the data link and return it
$ First = 1;
$ Prev = $ page-1;
$ Next = $ page + 1;
$ Last = $ pages;
// Display data at the command view layer
$ First_a = "<a onclick = 'init (". $ first. ") 'href = '#'> </a> ";
If ($ page> 1 ){
$ Prev_a = "<a onclick = 'init (". $ Prev. ") 'href = '#'> </a> ";
}
If ($ page <$ pages ){
$ Next_a = "<a onclick = 'init (". $ next. ") 'href = '#'> </a> ";
}
$ Last_a = "<a onclick = 'init (". $ last. ") 'href = '#'> </a> ";
@ $ STR = $ strtext. $ first_a. $ prev_a. $ next_a. $ last_a;
// Var_dump ($ Str );
$ Info = array ('str' => $ STR, 'info' => $ pageinfo );
Echo json_encode ($ info );