Home > php教程 > PHP源码 > php ajax 静态分页 过程形式

php ajax 静态分页 过程形式

PHP中文网
Release: 2016-05-25 17:13:26
Original
1355 people have browsed it

跳至

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

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">

Copy after login
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template