Php+ajax implementation of paging technology:
Based on the PHP and Ajax paging technology code, there are two PHP files, one is sn_inq.php, the other is sn_show.php, the previous PHP file called after a PHP file, the implementation of Ajax paging, run SN_INQ can achieve the effect, But you have to modify the database Oh. The specific code is as follows: Red label places to pay special attention to change Oh!
My database name is INV, the table name is SN, the fields are: sn_id,sn_plant,sn_sales,sn_act,sn_type,sn_sts .....
1.sn_inq.php
Getformvalue is used to get the values of all the input controls in the form and to make the input values a string to the server.
Note: If there is filesedset here, the form form must be placed in the fieldset, otherwise error.
Echo '
';
?>
2.sn_show.php:
Page function
function ShowPage (total) {
Global PAGE,PAGENAV,MIDDLE,NUM,PAGENUM,OFFSET,PREPG,NEXTPG;
Gets the value of the page in page=18, and if there is no page, the number of pages is 1.
Page=isset (_request[' page '])? Intval (_request[' page '): 1;
4 Paging connections per layer page bar
Middle = ' 4 ';
Show 10 data per page
num=10;
Get the total number of pages and the last page
Pagenum=ceil (Total/num);
Get home
Page=min (Pagenum,page);
Previous page
prepg=page-1;
Next page
nextpg= (Page==pagenum 0:page+1);
offset= (page-1) *num;
if (pagenum<=1) return false;
if (PREPG) {
pagenav.= ' onclick= ' javascript:showcomment (1); " > '. Iconv (' gb2312 ', ' gb2312 ', ' home '). ' ';
pagenav.= ' onclick= ' javascript:showcomment ('. Prepg. '); " > '. Iconv (' gb2312 ', ' gb2312 ', ' prev '). ' ';
}else{
Pagenav.= "". Iconv (' gb2312 ', ' gb2312 ', ' home '). "". " ";
Pagenav.= "". Iconv (' gb2312 ', ' gb2312 ', ' previous page '). ";
}
if (NEXTPG) {
pagenav.= ' onclick= ' javascript:showcomment ('. Nextpg. '); " > '. Iconv (' gb2312 ', ' gb2312 ', ' next page '). ' ';
pagenav.= ' onclick= ' javascript:showcomment ('. pagenum. '); " > '. Iconv (' gb2312 ', ' gb2312 ', ' last '). ' ';
}else{
Pagenav.= "". Iconv (' gb2312 ', ' gb2312 ', ' next page '). "". " ";
Pagenav.= "". Iconv (' gb2312 ', ' gb2312 ', ' last '). "". " ";
}
Pagenav.= '. Iconv (' gb2312 ', ' gb2312 ', ' total '). Pagenum. ' '. Iconv (' gb2312 ', ' gb2312 ', ' page ');
For (h= (Page-middle<1?1:page-middle); h<= (page+middle>pagenum?pagenum:page+middle); h++) {
if (h==page) {
pagenav.= " h ";
}else{
Pagenav.= "". Iconv (' gb2312 ', ' gb2312 ', h). " ";
}
}
Pagenav.= "";
Pagenav.=iconv (' gb2312 ', ' gb2312 ', ' go ');
Pagenav.= ""; for (i = 1; I <= pagenum;i++) {if (page = = i) {pagenav.= "". I." ";} Else{pagenav.= "". I." ";}} Pagenav.= "";
pagenav.= "Page";
return pagenav;
}
/ /connect to database
function Db_link ()
{
access_id = "root";
db_name = "INV";
@ db = mysql_connect (' localhost ', access_id, ' 831025 ') or
die ("Could does connect to database. Please contact with IT supporting Team ASAP. ");
mysql_query ("SET NAMES ' GBK '");
mysql_select_db (db_name);
return DB;
}
link = db_link ();
Get inquiry criteria, using post to get data is OK
Sn_id_1 = _request[' sn_id_1 '];
Sn_id_2 = _request[' sn_id_2 '];
Inquiry Total Pages
Sn_sql = "SELECT * from SN WHERE 1";
if (sn_id_1! = ") {
Sn_sql. = "and sn_id >= '". Sn_id_1. " ";
}
if (sn_id_2! = ") {
Sn_sql. = "and sn_id <= '". Sn_id_2. " ";
}
Sn_sql. = "ORDER by sn_id DESC";
Sn_res = mysql_query (Sn_sql);
Total = Mysql_num_rows (sn_res);
Show Page
Pageshow = ShowPage (total);
Inquiry current Page
Sn_sql. = "Limit Offset,num";
Sn_res = mysql_query (Sn_sql);
Sn_num = mysql_num_rows (sn_res);
Output inquiry result as XML
Header ("Content-type:text/xml");
if (Total > 0) {
Echo ' ';
Echo ' ';
Echo '<! [cdata['; <br/>echo ' <fieldset class= "inquiry" ><br/> <legend> list </legend> <br/><table class= "list" ><br/> <tr> <br /><th class= "header" >no </th> <br/><th class= "header" >sn </th> <br/><th class= "header" >plant </th> <br/><th class= "Header" >sales </th> <br/><th class= "header" >act </th> <br/><th class= "header" >type </th> <BR/> <th class= "header" >status </th> <br/><th class= "header" >release date </th> <br/><th class= "header" >approve date </th> <br/><th class= "header" >reject date </th> <br/><th class= "header" >cancel date </th> <br/><th class= "header" > Close Date </th> <br/> </tr> '; <br/>num = Offset;<br/>for (i = 0; I sn_num; i++) {<br/>sn_row = mysql_fetch_array (sn_res); <br/>if (i 2 = = 0) {<br/>echo ' <tr class= ' even ' style= ' cursor:hand ' > ' ; <br/>}else{<br/>echo ' <tr class= ' odd ' style= ' cursor:hand ' > ' <br/>}<br/>echo ' <td class= ' list center ' > ' ( num+1). ' </td> <BR/><td class= "list right blue" > sn_row[' sn_id ']. ' </td> <BR/><td class= "List Center" > sn_row[' sn_plant ']. ' </td> <BR/><TD class= "list right" > sn_row[' Sn_sales ']. ' </td> <BR/><td class= "List Center Red" > sn_row[' sn_act ']. ' </td> <BR/><td class= "List Center" > sn_row[' Sn_type ']. ' </td> <BR/><td class= "List Center" > sn_row[' sn_sts ']. ' </td> <BR/><td class= "list left" > substr (sn_row[' sn_rel_date '],0,10). ' </td> <BR/><td class= "list left" > substr (sn_row[' sn_apv_date '],0,10). ' </td> <BR/><td class= "list left" > substr (sn_row[' sn_rej_date '],0,10). ' </td> <BR/><td class= "list left" > substr (sn_row[' sn_can_date '],0,10). ' </td> <BR/><td class= "list left" > substr (sn_row[' sn_cls_date '],0,10). ' </td> <BR/> </tr> '; <br/>num++;<br/>}<br/>echo ' </table> '; <br/>echo '. pageshow. '; <BR/>echo ' </fieldset> '; <br/>echo ']]>';
Echo ' ';
}else{
Echo ' Find nothing ';
}
?>
http://www.bkjia.com/PHPjc/815027.html www.bkjia.com true http://www.bkjia.com/PHPjc/815027.html techarticle Php+ajax Implementation Paging technology: PHP and AJAX-based paging technology code, the following two PHP files, one is sn_inq.php, the other is sn_show.php, the previous PHP file called after a ph ...