php 之 模仿microsoft live分页类
来源:互联网 发布:linux挂载光盘命令 编辑:程序博客网 时间:2024/05/21 06:29
1,分页类:myPager.php
------------------------------------------------------------------------------------------
<?php
/*project: test
author: yuhui
date: 2009-4-25
profile: 分页类
*/
Class myPager
{
var $page_id = 0;//当前页
var $pages = 0;//总页数
var $con ;//数据连接
var $tale ;//sql
var $where; //条件
var $rs ;//结果集
var $x =0;//总记录数
var $size = 0;//页记录数
var $arr = array(10);//分页序号
function myPager(&$con,$table,$where,$size,$page_id)
{
//初始化变量
$this->table = $table;
$this->where = $where;
$this->con = $con;
$this->size = $size;
$this->page_id = $page_id;
//查询
$this->rs = $con->GetActiveRecords($table,$where." limit ".$this->page_id*$this->size.",".$this->size);
$this->x = $con->GetOne("select count(*) from ".$table." where ".$where);
$this->pages = $this->x > $this->size ? ($this->x - $this->x%$this->size)/$this->size + 1 : 1;
$temp = $this->page_id >= 10 ? ($this->page_id - $this->page_id%10)/10 :0;
for($i = 0, $j = $temp*10 ;$i < 10 && $j < $this->pages; $i++,$j++)
{
$this->arr[$i] = $j;
}
}
}
?>
2,使用:goods_list.php
----------------------------------------------------------------------------------
<?php
$where = $_GET['where'];//类别id
$page_id = $_GET['page_id'];//请求页面id
$con = ADONewConnection("mysql");
$con->Connect($server,$username,$password,$database);
mysql_query("set names utf8");
$table = "t_goods";
$size = 10;
$pager = new myPager($con,$table,"g_type=2",$size,$page_id);
$smarty->assign("pager",$pager);
$smarty->assign("arr",$pager->arr);
$smarty->assign("rs",$pager->rs);
$smarty->display("goods_list.html");
?>
3,显示:goods_list.html
------------------------------------------------------------------------------------
<body>
--------------------------------------------------------------变量
<input type="hidden" id="where" value="{{$pager->where}}"/>
<input type="hidden" id="page_id" value="{{$pager->page_id+1}}"/>
<input type="hidden" id="pages" value="{{$pager->pages}}"/>
<table style="width:100%; height:35px;">
<tr>
--------------------------------------------------------------分页栏
<td>共{{$pager->x}}件商品 {{$pager->page_id+1}}/{{$pager->pages}}</td>
<td align="left">
-----------------------上一页
<div id="pre" style=" width:60px; height:30px; float:left; border:solid 1px green; margin:2px; line-height:30px;" align="center" onMouseOver="this.style.background='#ADDEAD'" onMouseOut="this.style.background='#ffffff' " onClick="go({{$pager->pages}});" >上一页</div>
-------------------------小方块
{{section name=loop loop=$arr}}
<div id="{{$arr[loop]+1}}" style=" width:30px; height:30px; float:left; border:solid 1px green; margin:2px; line-height:30px;" align="center" onMouseOver="this.style.background='#ADDEAD'" onMouseOut="this.style.background='#ffffff' " onClick="go(this.id-1);">{{$arr[loop]+1}}</div>
{{/section}}
--------------------------下一页
<div id="next" style=" width:60px; height:30px; float:left; border:solid 1px green; margin:2px; line-height:30px;" align="center" onMouseOver="this.style.background='#ADDEAD'" onMouseOut="this.style.background='#ffffff' " onClick="go({{$pager->page_id+1}});" >下一页</div>
</td></tr></table>
<hr/>
<div >
{{section name=loop loop=$rs}}
{{$rs[loop]->g_name}}
<hr color="gray" />
{{/section}}
</div>
4,美化:
--------------------------------------------------------------
function pager_init()
{
//<!--改变当前页码底色 -->
var page_id = document.getElementById('page_id').value;
var temp = document.getElementById(page_id);
temp.style.background = "#ADDEAD";
temp.onmouseover = null;
temp.onmouseout = null;
temp.onclick = null;
//<!--上一页 -->
if(document.getElementById('1') != null )
{
document.getElementById('pre').style.display = "none";
}
//<!--下一页 -->
var pages= document.getElementById('pages').value;
if(document.getElementById(pages+1) != null)
{
document.getElementById('next').style.display = "none";
}
}
pager_init();
5,跳转
--------------------------------------------------------------
function go(num)
{
var where = document.getElementById('where').value;
location.href = "goods_list.php?where="+where+"&page_id="+num;
}
--------------------------------------------------------------end------------------------------------------
- php 之 模仿microsoft live分页类
- 模仿PHP写的ASP 分页
- php之分页类代码
- 模仿tmall首页live div
- Microsoft Live全景图
- Microsoft "Live.Com" Rocks :-)
- Microsoft Office Live
- Microsoft Live Mesh用后感
- PHP随笔一之分页类
- php 之 adodb 分页
- php之分页模块
- 【PHP】php 分页类
- 模仿google分页代码
- php封装类模仿链式操作
- PHP分页代码 PHP分页类 PHP分页实例
- Microsoft Office Live Communications Setup
- Microsoft Office Live For Dummies
- 从 Live Essastional 到 Microsoft
- 网络管理中的常用命令
- MIME TYPE 大全
- Cisco IOS 基本命令集
- ADO.NET2.0 Querying Large Result Sets Asynchronously(ADO.NET 异步操作)
- Windows XP下屏蔽Ctrl_Alt_Del键的方法
- php 之 模仿microsoft live分页类
- WINDOWS下进程详解
- 12条有用的as代码
- 数组和指针
- Status: 500 Internal Server Error
- PHP 5.0 的变化与PHP 6.0 展望
- 今年的生活目标
- 请多多指教啊!
- 亲密接触C可变参数函数