Home > Backend Development > PHP Tutorial > php 分页总数怎么获得

php 分页总数怎么获得

WBOY
Release: 2016-06-13 13:35:45
Original
1743 people have browsed it

php 分页总数如何获得
我写了一个php分页,我现在 select * from user limit ".($page-1)." , ".$rows 只能获得到每次多少条,我想获得总共多少条,怎么获得,现在获得是getRowNum();

function getRowNum()
  {
  return mysql_num_rows($this->res);
  }

require_once ('../db/db.php');
$db=new DataAccess();
$con=$db->connect();
$rows = $_POST['rows'];
$page = $_POST['page'];
$sql="select * from user limit ".($page-1)." , ".$rows; //分页的sql
$result=$db->query($sql);
$row_num =$db->getRowNum();//只能获得到当前多少条



------解决方案--------------------
需要单独执行一次 select count(*) from user
------解决方案--------------------

探讨

引用:

分页就是这样BT。我一般不写的。我直接用项目写好的类,传值就行。


不写不等于不是这样实现的嘛.只不过是弄了块遮羞步而已,其实也很正常呀,你不读取数据库的数据,如何知道有多少条数据准备分页...

------解决方案--------------------
探讨

谁有现成的方法最好分享一下,谢谢
Related labels:
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