【急】php分页 求一个php分页类,要有详细的使用例子。
我也有很多少分页类,但很多都没有说明怎么用的
请高手给个实例好吗
我也有很多少分页类,但很多都没有说明怎么用的
请高手给个实例好吗
解决方案 »
- PHP 查询mysql表 中的默认值 并提出来
- PHP基础性问题请教,请大家帮忙,谢谢
- 急!!!插入到数据库的数据,取出来某些地方多了 \
- 正则问题,100分相送!!!!万分感谢!
- 关于页面之间的传值问题...
- 生成PDF文件的時候如何竖直顯示文字﹖
- 类似于google 土豆的搜索框 我的做法是onkeydown显示下拉框 失去焦点时隐藏 但是点下拉框里的内容的时候焦点也没了 这是也隐藏了 怎么办?
- 执行insert into语句为什么不报错?
- 新手请教zend studio调试
- php 正则提取XML 指定内容方法?求大拿帮忙(史上最难)
- 类似 java的 Application
- 学习PHP,用ZEND STUDIO还是EASYELISPE
function trans_pages($js_func_name,$js_parameters=0,$total,$pagesize=10,$nowpage=1){
if($nowpage<1){$rowpage=1;}
if($total%$pagesize){
$totalpage=intval($total/$pagesize)+1;
}else{
$totalpage=intval($total/$pagesize);
}
if($nowpage<$totalpage && $totalpage!=1){
$pageup=$nowpage-1;
$pagedown=$nowpage+1;
$pageup_string="<span style='color:#60693e;text-decoration:underline;cursor:pointer;' onmouseover='text_css(this)' onclick=\"eval($js_func_name($pageup $js_parameters))\">上一页</span>";
$pagedown_string="<span style='color:#60693e;text-decoration:underline;cursor:pointer;' onmouseover='text_css(this)' onclick=\"eval($js_func_name($pagedown $js_parameters))\">下一页</span>";
}elseif($totalpage<=1){
$pageup=1;
$pagedown=1;
$pageup_string="<span>上一页</span>";
$pagedown_string="<span>下一页</span>";
}elseif($nowpage>=$totalpage){
$nowpage=$totalpage;
$pageup=$nowpage-1;
$pagedown=$totalpage;
$pageup_string="<span style='color:#60693e;text-decoration:underline;cursor:pointer;' onmouseover='text_css(this)' onclick=\"eval($js_func_name($pageup $js_parameters))\">上一页</span>";
$pagedown_string="<span>下一页</span>";
}
if($pageup<1){
$pageup=1;
$pageup_string="<span>上一页</span>";
} $array=array("up"=>$pageup,"down"=>$pagedown,"upstring"=>$pageup_string,"downstring"=>$pagedown_string);
return $array;
}
给你个精简过的分页trans_pages($js_func_name,$total,$nowpage=1,$js_parameters=0,$pagesize=10)
参数1:js函数名 也是分页调用的js函数
参数2: ...
参数3:js参数
..........
<?php
class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $high;
var $limit;
var $return;
var $default_ipp =15;
var $querystring;
var $ipp="ipp";
var $page="page";
function Paginator()
{
$this->current_page = 1;
$this->mid_range = 7;
$this->items_per_page = (!empty($_GET[$this->ipp])) ? $_GET[$this->ipp]:$this->default_ipp;
} function paginate()
{
if(isset($_GET[$this->ipp]))
{
if($_GET[$this->ipp] == 'All')
{
$this->num_pages = ceil($this->items_total/$this->default_ipp);
$this->items_per_page = $this->default_ipp;
}
else
{
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
}
}
else
{
$this->num_pages = ceil($this->items_total/$this->default_ipp);
$this->items_per_page = $this->default_ipp;
}
if(isset($_GET[$this->page]))
{
$this->current_page = (int) $_GET[$this->page]; // must be numeric > 0
}
if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1;
if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages;
$prev_page = $this->current_page-1;
$next_page = $this->current_page+1; if($_GET)
{
$args = explode("&",$_SERVER['QUERY_STRING']);
foreach($args as $arg)
{
$keyval = explode("=",$arg);
if($keyval[0] != $this->page And $keyval[0] != $this->ipp) $this->querystring .= "&" . $arg;
}
}
/*
if($_POST)
{
foreach($_POST as $key=>$val)
{
if($key != $this->page And $key != $this->ipp) $this->querystring .= "&$key=$val";
}
}
*/
if($this->num_pages > 10)
{
$this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?$this->page=$prev_page&$this->ipp=$this->items_per_page$this->querystring\">« 上一页</a> ":"<span class=\"inactive\" href=\"#\">« 上一页</span> ";
/* $this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?$this->page=$prev_page&$this->ipp=$this->items_per_page$this->querystring\"><img src='/resource/image/index_44.png' /></a> ":"<span class=\"inactive\" href=\"#\"><img src='/resource/image/index_44.png' /></span> "; */ $this->start_range = $this->current_page - floor($this->mid_range/2);
$this->end_range = $this->current_page + floor($this->mid_range/2); if($this->start_range <= 0)
{
$this->end_range += abs($this->start_range)+1;
$this->start_range = 1;
}
if($this->end_range > $this->num_pages)
{
$this->start_range -= $this->end_range-$this->num_pages;
$this->end_range = $this->num_pages;
}
$this->range = range($this->start_range,$this->end_range); for($i=1;$i<=$this->num_pages;$i++)
{
if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
// loop through all pages. if first, last, or in range, display
if(isset($_GET[$this->page]))
{
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
$this->return .= ($i == $this->current_page And $_GET[$this->page] != 'All') ? "<a title=\"第".$i."页\" class=\"current\" href=\"#\">".$i."</a> ":"<a class=\"paginate\" title=\"第".$i."页\" href=\"$_SERVER[PHP_SELF]?$this->page=$i&$this->ipp=$this->items_per_page$this->querystring\">".$i."</a> ";
}
}
else
{
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
$this->return .= ($i == $this->current_page) ? "<a title=\"第".$i."页\" class=\"current\" href=\"#\">".$i."</a> ":"<a class=\"paginate\" title=\"第".$i."页\" href=\"$_SERVER[PHP_SELF]?$this->page=$i&$this->ipp=$this->items_per_page$this->querystring\">".$i."</a> ";
}
}
if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
}
if(isset($_GET[$this->page]))
{
$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET[$this->page] != 'All')) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?$this->page=$next_page&$this->ipp=$this->items_per_page$this->querystring\">下一页 »</a>\n":"<span class=\"inactive\" href=\"#\">» 下一页</span>\n";
/*$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET[$this->page] != 'All')) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?$this->page=$next_page&$this->ipp=$this->items_per_page$this->querystring\"><img src='/resource/image/index_42.png' /></a>\n":"<span class=\"inactive\" href=\"#\"><img src='/resource/image/index_42.png' /></span>\n"; */
/*
$this->return .= ($_GET[$this->page] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">显示所有</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?$this->page=1&$this->ipp=All$this->querystring\">显示所有</a> \n"; */
}
else
{
$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10)) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?$this->page=$next_page&$this->ipp=$this->items_per_page$this->querystring\">下一页 »</a>\n":"<span class=\"inactive\" href=\"#\">» 下一页</span>\n";
/*$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10)) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?$this->page=$next_page&$this->ipp=$this->items_per_page$this->querystring\"><img src='/resource/image/index_42.png' /></a>\n":"<span class=\"inactive\" href=\"#\"><img src='/resource/image/index_42.png' /></span>\n"; */
/*
$this->return .= ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">显示所有</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?$this->page=1&$this->ipp=All$this->querystring\">显示所有</a> \n"; */
}
}
else
{
for($i=1;$i<=$this->num_pages;$i++)
{
$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\"><b>[$i]</b></a> ":"<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?$this->page=$i&$this->ipp=$this->items_per_page$this->querystring\">[$i]</a> ";
}
// $this->return .= "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?$this->page=1&$this->ipp=All$this->querystring\">All</a> \n";
}
$this->low = ($this->current_page-1) * $this->items_per_page;
if(isset($_GET[$this->page]))
{
$this->high = ($_GET[$this->page] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1;
}
if($this->low < 0)
{
$this->low=0;
}
if(isset($_GET[$this->page]))
{
$this->limit = ($_GET[$this->page] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
else
{
$this->limit =" LIMIT 0,$this->items_per_page";
}
} function display_items_per_page()
{
$items = '';
$ipp_array = array(10,15,20,25,50,100,'All');
foreach($ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n";
return "<span class=\"paginate\">每页显示:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?$this->page=1&$this->ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n";
} function display_jump_menu()
{
$option=null;
for($i=1;$i<=$this->num_pages;$i++)
{
$option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n";
}
return "<span class=\"paginate\"> 到第 </span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?$this->page='+this[this.selectedIndex].value+'&$this->ipp=$this->items_per_page$this->querystring';return false\">$option</select> 页\n";
}
function display_text_menu()
{
$time=time();
return "<span class=\"paginate\">到第</span><input type='text' maxlength='3' size=2 style='width:25' id='display__text__menu__{$time}'>
页
<input align=absmiddle type=image src='../resources/image/index_42.png' onclick=\"window.location='$_SERVER[PHP_SELF]?$this->page='+document.getElementById('display__text__menu__{$time}').value+'&$this->ipp=$this->items_per_page$this->querystring';return false\" value='查看' />\n";
}
function display_pages()
{
return $this->return;
}
}
?>
include("adodb/adodb.inc.php");//必须导入的
include("adodb/toexport.inc.php");//分页用的
include("adodb/adodb-pager.inc.php");$host="localhost";
$dbname="root";
$dbpass="root";
$db="*****";$conn=ADONewConnection("mysql");//选择需要链接的数据库种类,这里是链接mysql数据库$conn->Connect($host,$dbname,$dbpass,$db);//链接$conn->Execute("set names gb2312");
$sql="select * from *****";$rs=$conn->Execute($sql);$pager=new ADODB_Pager($conn,$sql);
pager->Render($rows_per_page=3);//每页显示3条记录
?>