php ajax 静态分页 过程形式
程序员文章站
2022-04-29 11:11:48
...
跳至
js 端 及判断1?now-1:1; break; case 'next': target=now+1>allpage?now:1; break; case 'last': target=allpage>0?allpage:1; break; case 'constans': target=$('#selpage').val()>0?$('#selpage').val():1; default : target=1; } var data="check="+act+"&nowpage="+now+"&perpage="+per+'&target='+target; alert(data); return data; } //执行第一页 function goPageFirst() { var param=getData('first'); http_post(param); } //执行上一页 function goPagePrev() { var param=getData('prev'); http_post(param); } //执行下一页 function goPageNext() { var param=getData('next'); http_post(param); } //执行最后页 function goPageLast() { var param=getData('last'); http_post(param); } //选中到指定页面 function goPage() { var param=getData('constans'); http_post(param); } //post 请求数据加载 function http_post(db) { $.post('./mysql.php',db,function(data){ responseAjax(data); },'text'); } //返回数据的调处理 function responseAjax(msg) { //alert(msg); //alert(msg.content); //$('#listDiv').html(msg.content); $('#listDiv').html(msg); } server端 判断及实现 //@autor 499188204@qq.com mb_internal_encoding('gb2312'); $con=mysql_connect("127.0.0.1","root","12345678") or die("连接失败"); $m=mysql_select_db("ec",$con); $sql = 'SELECT `attr_id`,`cat_id`,`attr_name` FROM `ecs_attribute` '; $rs = mysql_query($sql ); $count = mysql_num_rows($rs); //返回记录总数 //echo $count; //总记录数 //每页的记录数 10 //求总页数 ceil($count/10) //echo ''; if(!isset($_POST['check'])) { $set['id']=0; die('no access please!'); } if(isset($_POST['perpage']) && $_POST['perpage']>0 ) { $per=$_POST['perpage']; } else { $per=15; } $page = ceil($count/$per); //echo $page; if(!isset($_POST['nowpage'])) { $nowPage=1; } else { $nowPage = $_POST['nowpage']; } $start = ($nowPage-1)*$per+1; $sql = 'select `attr_id`,`cat_id`,`attr_name` from `ecs_attribute` limit '.$start.','. $per; //$sql = 'select `attr_id`,`cat_id`,`attr_name` from `ecs_attribute` limit 10 offset 20'; $rs = mysql_query($sql ); $str = "属性编号类型编号属性名字"; while($row = mysql_fetch_assoc($rs)){ $str .=''.$row['attr_id'].''.$row['cat_id'].''.$row['attr_name'].''; } $str.="总计".$count."个记录分为".$page."页当前第".$nowPage."页,每页 | 第一页 上一页 下一页 最末页 "; for($i=1;$i ".$i.""; } else { $str .= "".$i.""; } } $str .=""; echo mb_convert_encoding($str,'UTF-8','gb2312'); //$set['content']=$str; //echo json_encode($set); ?> .code_report{float:right} .code_report p{ float: left; margin-left: 5px; background: url("/img/ask-icon.gif") no-repeat; padding: 6px 0 6px 15px; padding-left: 15px; height: 16px;} .code_report a{ background: url("/img/ask-icon.gif") 0 -160px no-repeat;padding-left: 20px; line-height: 15px;height: 16px; color: #333; text-decoration: none; display:inline-block; zoom:1; vertical-align: middle;} .code_report em{ height: 28px; line-height:28px; width: 14px; display: inline-block; float: left; background: url("/img/ask-icon.gif") top right;} " _ue_custom_node_="true">