PHP分页

发布时间:2020-07-02 15:36:11 作者:zhuchengdie
来源:网络 阅读:325

<?php

$conn=mysql_connect("localhost","root","");

//$result2=mysql_db_query("hello_world", "insert into hello_table values ('add1',8)",$conn);

// $result2=mysql_db_query("hello_world", "delete from hello_table where hello_column='add1'",$conn);

$resultNum=mysql_db_query("hello_world","select count(*) from hello_table order by hello_column" ,$conn);

$RSS=mysql_fetch_array($resultNum);

$num=$RSS[0];

if(empty($_GET['page'])){

$page=0;

}else{

$page=$_GET['page'];

if($page<0){

$page=0;

}

if($page>=ceil($num/5)){

$page=ceil($num/5)-1;

}

 

}

$excute="select * from hello_table order by hello_column limit ".($page*5).",5 ";

$result=mysql_db_query("hello_world",$excute ,$conn);

$row=mysql_fetch_row($result);

for($i=0;$i<mysql_num_fields($result);$i++){

echo mysql_field_name($result, $i)." ";

}

echo "<br>";

while($row=mysql_fetch_row($result)){

for($i=0;$i<mysql_num_fields($result);$i++){

echo $row[$i]." ";

}

echo "<br>";

}

mysql_free_result($result);

mysql_close($conn);

 

 

?>

<

a href="test.php?page=0">FirstPage</a>

<

a href="test.php?page=<?=($page-1) ?>">PrevPage</a>

<

a href="test.php?page=<?=($page+1) ?>">NextPage</a>

<

a href="test.php?page=<?=ceil($num/5)-1 ?>">LastPage</a>

 =====================================================================

 

怎么分段,当前在第几段 (每页有几条,当前再第几页

 

前10条记录:select * from table limit 0,10

第11至20条记录:select * from table limit 10,10

第21至30条记录:select * from table limit 20,10

 

 

 

(当前页数 - 1 )X 每页条数 , 每页条数

Select * from table limit ($Page- 1) * $PageSize, $PageSize

推荐阅读:
  1. php 分页 分页类 简单实用
  2. php 分页原理

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php 分页

上一篇:关于Keras中categorical_crossentropy函数的详细用法

下一篇:关于Spring Boot2.3新特性分层JAR的使用说明

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》