这个php分页类怎么用

来源:百度知道 编辑:UC知道 时间:2024/05/17 03:05:48
这是个php,WAP分页类,请教怎么调用,循环体在那里写,SQL语句再那里写
<?php
class page_list
{
var $total_page;
var $now_page;
var $list_page;
var $next_page; //计算总页数函数,$rows表示总的记录个数,$list_rows表示每页要显示的条数
function totalpage($rows,$list_rows){
$this->total_page=ceil($rows/$list_rows);
$nums=$this->total_page;
return $nums;
} //计算当前页的函数,$page为_post或_get方法传过来的变量
function nowpage($page){
if(!isset($page) || $page<1){
$this->now_page=1;
}
else {
$this->now_page=$page;
}
$pages=$this->now_page;
return $pages;
} //显示上一页,下一页
function display($rows,$list_rows,$page,$url){
$this->list_page=$page-1;
$this->next_page=$page+1;
if(strpos($url,’page=’)!=’’)
$url=substr($url,0,strpos($url,’page=’));
else
$url.=’&’;
if($this->nowpage($page)==1){
echo convert_character(’共’).$this->totalpage($rows,$list_rows).convert_char

介绍下我编写的分页

<?
$conn = mysql_connect ("localhost","root","")||die("无法连接数据库");
mysql_select_db("2009exhi")||die("选择数据库失败");

$filename="分页显示记录.php"; //定义本程序文件名(必须和本文件的名称一样,且包含扩展名)
$tablename="news"; //定义查询的表名
$turn="order by id desc"; //定义查询的排序方式(本例子定义了以id降序查询)
$oncondition="where id>18"; //定义查询条件(本例子定义了以id>18为查询条件)

$execc="select count(*) from ".$tablename." ".$oncondition;
$resultc=mysql_query($execc);
$rsc=mysql_fetch_array($resultc);

$num=$rsc[0]; //计算总记录数
$perpage=4; //定义每页显示记录数(自定义)
$totalpage=ceil($num/$perpage); //计算总页数

$page=$_GET['page'];
if($page<0)$page=0;
if($page>=ceil($num/$perpage))$page=ceil($num/$perpage)-1;
$nowpage=$page+1; //计算当前第几页