Today to see the silent explanation of the page, think of as if the original area for a long time no one post, on the way to the silent extension, to a Php+ajax page demonstration bar, OK, come, first of all, we are still the basic AJAX development Framework:
Copy the Code code as follows:
var Http_request=false;
function send_request (URL) {//Initialize, specify handler function, send request functions
Http_request=false;
Start initializing the XMLHttpRequest object
if (window. XMLHttpRequest) {//mozilla browser
Http_request=new XMLHttpRequest ();
if (http_request.overridemimetype) {//Set MIME category
Http_request.overridemimetype ("Text/xml");
}
}
else if (window. ActiveXObject) {//ie browser
try{
Http_request=new ActiveXObject ("msxml2.xmlhttp");
}catch (e) {
try{
Http_request=new ActiveXObject ("Microsoft.XMLHTTP");
}catch (e) {}
}
}
if (!http_request) {///exception, creation of object instance failed
Window.alert ("Failed to create XMLHTTP Object! ");
return false;
}
Http_request.
Determine how to send the request, URL, and whether to synchronize execution of the next snippet of code
Http_request.open ("GET", url,true);
Http_request.send (NULL);
}
function to process return information
function ProcessRequest () {
if (http_request.readystate==4) {//Judging object state
if (http_request.status==200) {//information has been successfully returned to start processing information
document.getElementById (reobj). Innerhtml=http_request.responsetext;
}
else{//page is not working
Alert ("The page you requested is not working!") ");
}
}
}
function Dopage (obj,url) {
document.getElementById (obj). innerhtml= "reading data ...";
Send_request (URL);
Reobj=obj;
}
Content I put in a div display, when the page turn action generated, the use of Ajax Update Div to achieve page flipping effect this is the content display code:
Copy the Code code as follows:
Header ("CONTENT-TYPE:TEXT/HTML;CHARSET=GBK");//output code to avoid Chinese garbled
?>
<title>Ajax Paging Demo</title>
$page =isset ($_get[' page ')? Intval ($_get[' page ')): 1; This is to get the value of page in Page=18, if there is no page, then the number of pages is 1.
$num = 10; Show 10 data per page
$db =mysql_connect ("localhost", "root", "7529639"); Create a database connection
mysql_select_db ("Cr_download"); Select the database to manipulate
/*
First we want to get the database in the end how much data in order to determine the specific number of pages, the specific formula is
The total database is divided by the number of bars displayed per page.
That is to say, 10/3=3.3333=4 will be in one.
*/
$result =mysql_query ("SELECT * from Cr_userinfo");
$total =mysql_num_rows ($result); Querying all the data
$url = ' test.php ';//Get page URL
Page Count
$pagenum =ceil ($total/$num); Get the total number of pages and the last page
$page =min ($pagenum, $page);//Get home
$PREPG = $page -1;//Previous page
$NEXTPG = ($page = = $pagenum? 0: $page + 1);//Next page
$offset = ($page-1) * $NUM; Gets the value of the first parameter of the limit, assuming that the first page is (1-1) *10=0, and the second page is (2-1) *10=10.
Start Page navigation bar code:
$pagenav = "Show". ($total? ($offset + 1): 0). "-". Min ($offset +10, $total)."Records, a total of $total records ";
If only one page jumps out of the function:
if ($pagenum <=1) return false;
$pagenav. = "Home";
if ($PREPG) $pagenav. = "front page"; else $pagenav. = "front page";
if ($NEXTPG) $pagenav. = "Back Page"; else $pagenav. = "Back Page";
$pagenav. = "Last";
$pagenav. = "Page, total $pagenum page ";
If the number of pages passed in is greater than the total number of pages, an error message is displayed
If ($page > $pagenum) {
Echo "Error:can not Found the page". $page;
Exit;
}
$info =mysql_query ("select * from Cr_userinfo limit $offset, $num"); Get the data you need to display for the number of pages
while ($it =mysql_fetch_array ($info)) {
Echo $it [' username '];
echo "
";
}//Display data
Echo
";
echo $pagenav;//Output paging navigation
?>
The key to paging is to call the Dopage () function when you turn the page, and then use the callback information to update the contents of the Div. Server-side Core code:
Copy the Code code as follows:
Header ("CONTENT-TYPE:TEXT/HTML;CHARSET=GBK");//output code to avoid Chinese garbled
$page =isset ($_get[' page ')? Intval ($_get[' page ')): 1; This is to get the value of page in Page=18, if there is no page, then the number of pages is 1.
$num = 10; Show 10 data per page
$db =mysql_connect ("localhost", "root", "7529639"); Create a database connection
mysql_select_db ("Cr_download"); Select the database to manipulate
/*
First we want to get the database in the end how much data in order to determine the specific number of pages, the specific formula is
The total database is divided by the number of bars displayed per page.
That is to say, 10/3=3.3333=4 will be in one.
*/
$result =mysql_query ("SELECT * from Cr_userinfo");
$total =mysql_num_rows ($result); Querying all the data
$url = ' test.php ';//Get page URL
Page Count
$pagenum =ceil ($total/$num); Get the total number of pages and the last page
$page =min ($pagenum, $page);//Get home
$PREPG = $page -1;//Previous page
$NEXTPG = ($page = = $pagenum? 0: $page + 1);//Next page
$offset = ($page-1) * $NUM; Gets the value of the first parameter of the limit, assuming that the first page is (1-1) *10=0, and the second page is (2-1) *10=10.
Start Page navigation bar code:
$pagenav = "Show". ($total? ($offset + 1): 0). "-". Min ($offset +10, $total)."Records, a total of $total records ";
If only one page jumps out of the function:
if ($pagenum <=1) return false;
$pagenav. = "Home";
if ($PREPG) $pagenav. = "front page"; else $pagenav. = "front page";
if ($NEXTPG) $pagenav. = "Back Page"; else $pagenav. = "Back Page";
$pagenav. = "Last";
$pagenav. = "Page, total $pagenum page ";
If the number of pages passed in is greater than the total number of pages, an error message is displayed
If ($page > $pagenum) {
Echo "Error:can not Found the page". $page;
Exit;
}
$info =mysql_query ("select * from Cr_userinfo limit $offset, $num"); Get the data you need to display for the number of pages
while ($it =mysql_fetch_array ($info)) {
Echo $it [' username '];
echo "
";
}//Display data
Echo
";
echo $pagenav;//Output paging navigation
?>
The above describes the PHP page navigation Ajax PHP page presentation, including the content of the PHP page navigation, I hope that the PHP tutorial interested in a friend helpful.