PHP + AJAX paging

Source: Internet
Author: User
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" ";For ($ a = 0; $ a <$ num; $ a ++){Echo" \ N ";Echo" ";Echo" ";Echo" ";Echo" ";Echo" ";Echo" ";# Echo" ";
ID Name Author Press ISBN No. Type Price
". $ Pipeline name [$ a]."". $ Name [$ a]."". $ Author [$ a]."". $ Publisher [$ a]."". $ Isbn [$ a]."". $ Type [$ a]."

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.