PHP+Ajax implements paging technology_PHP tutorial

WBOY
Release: 2016-07-13 10:27:51
Original
1109 people have browsed it

PHP+Ajax implementation of paging technology:

Paging technology code based on php and ajax. There are two php files below, one is sn_inq.php and the other is sn_show.php. The former php file calls the next php file to implement ajax paging. Just run sn_inq. To achieve the effect, you have to modify the database. The specific code is as follows: Pay special attention to modifications in the areas marked in red!

My database name is inv, the table name is sn, and 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 input controls in the form, and combine the input values ​​into a string and send it to the server.

//注意:此处如果有filesedset的话,form表单一定要放在fieldset里面,否则出错。
echo '







SN
to 

onClick="showcomment(1)"/>


';

?>


2.sn_show.php:

//page function
function showpage(total){
global page,pagenav,middle,num,pagenum,offset,prepg,nextpg;
//Get the value of page in page=18. If page does not exist, then the page number is 1.
page=isset(_REQUEST['page'])?intval(_REQUEST['page']):1;
//Each layer of paging bars displays 4 paging connections
middle = '4';
//Display 10 pieces of data per page
num=10;
//Get the total number of pages, which is also the last page
pagenum=ceil(total/num);
//Get homepage
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','Homepage'). ' ';
pagenav.=' onclick="javascript:showcomment('.prepg.');">'.iconv('gb2312','gb2312',' Previous page').' ';
}else{
pagenav.="".iconv('gb2312','gb2312','Homepage').""." ";
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 page').' ';
}else{
pagenav.="".iconv('gb2312','gb2312','next page').""." ";
pagenav.="".iconv('gb2312','gb2312','Last page').""." ";
}

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 to ');

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 not 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,用 POST取得数据也行
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 ' echo '


LIST














';
num = offset;
for (i = 0; i < sn_num; i++) {
sn_row = mysql_fetch_array(sn_res);
if (i % 2 == 0) {
echo '';
}else{
echo '';
}
echo'











';
num++;
}
echo '
No SN Plant Sales Act Type Status Release Date Approve Date Reject Date Cancel Date Close Date
'.(num+1).' '.sn_row['sn_id'].' '.sn_row['sn_plant'].' '.sn_row['sn_sales'].' '.sn_row['sn_act'].' '.sn_row['sn_type'].' '.sn_row['sn_sts'].' '.substr(sn_row['sn_rel_date'],0,10).' '.substr(sn_row['sn_apv_date'],0,10).' '.substr(sn_row['sn_rej_date'],0,10).' '.substr(sn_row['sn_can_date'],0,10).' '.substr(sn_row['sn_cls_date'],0,10).'
';
echo '
'.pageshow.'
';
echo '
';
echo ']]>';
echo '';
}else{
echo 'find nothing';
}

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/815027.htmlTechArticlePHP+Ajax to implement paging technology: Paging technology code based on php and ajax. There are two php files below, one It is sn_inq.php, and the other one is sn_show.php. The previous php file calls the next ph...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template