PHP + AJAX pagination & lt ;! DOCTYPEhtmlPUBLIC & quot;-W3CDTDXHTML1.0TransitionalEN & quot; www. w3.orgTRxhtml1DTDxhtml1-transitional. dtd & quot; & gt; & lt; htmlxmlns & quot; PHP + AJAX pagination
Script
Function viewpage (p ){
If (window. XMLHttpRequest ){
Var xmlReq = new XMLHttpRequest ();
} Else if (window. ActiveXObject ){
Var xmlReq = new ActiveXObject ('Microsoft. xmlhttp ');
}
Var formData = "page =" + p;
XmlReq. onreadystatechange = function (){
If (xmlReq. readyState = 4 ){
Document. getElementById ('content2'). innerHTML = xmlReq. responseText;
}
}
XmlReq. open ("post", "d. php", true );
XmlReq. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded ");
XmlReq. send (formData );
Return false;
}
Script
# Header ("Content-Type: text/html; charset = GB2312 ");
$ Pagesize = 10;
// Echo $ _ POST ['Page'];
$ Db = mysql_connect ("localhost", "root", ""); // create a database connection
Mysql_query ("set names gbk ");
Mysql_select_db ("pagelist ");
$ Result = mysql_query ("select * FROM sheet1", $ db );
$ Myrow = mysql_fetch_array ($ result );
$ Numrows = mysql_num_rows ($ result );
$ Pages = intval ($ numrows/$ pagesize );
If ($ numrows % $ pagesize)
$ Pages ++;
If (isset ($ _ POST ['Page']) {
$ Page = intval ($ _ POST ['Page']);
}
Else {
// Set it to the first page
$ Page = 1;
}
$ First = 1;
$ Prev = $ page-1;
$ Next = $ page + 1;
$ Last = $ pages;
// Calculate the record offset
$ Offset = $ pagesize * ($ page-1 );
// Read the specified number of records
// $ Result = mysql_query ("select 'id', count (*) from ". book. "group by 'id' order by id desc limit $ offset, $ pagesize ");
$ Result = mysql_query ("select * from sheet1 limit $ offset, $ pagesize ");
$ Num = mysql_num_rows ($ result );
While ($ row = mysql_fetch_array ($ result, $ db )){
$ Pipeline name [] = $ row [0];
$ Name [] = $ row [1];
$ Author [] = $ row [2];
$ Publisher [] = $ row [3];
$ Isbn [] = $ row [4];
$ Type [] = $ row [5];
$ Smallpic [] = $ row [6];
// $ Countpeople [] = $ row [1];
}
Echo"
\ N ";Echo"
\ N ";Echo"
ID |
Name |
Author |
Press |
ISBN No. |
Type |
Price | ";For ($ a = 0; $ a <$ num; $ a ++){Echo"
\ N ";Echo"
". $ Pipeline name [$ a]." | ";Echo"
". $ Name [$ a]." | ";Echo"
". $ Author [$ a]." | ";Echo"
". $ Publisher [$ a]." | ";Echo"
". $ Isbn [$ a]." | ";Echo"
". $ Type [$ a]." | ";# Echo"
| ";