21,893
社区成员




//outboxdao.php
include_once("../../comm/dao/DBConnection.php");
class outboxdao{
/**
* 得到数组
*/
public function getList($offset,$pageSize){
$dbconndb = new DBConnection();
$conn = $dbconndb->getConnection();
mysql_select_db("kalkun");
mysql_query("set names gb2312");
$sql="select ID, DestinationNumber,TextDecoded ,InsertIntoDB from outbox order by ID asc limit ".$offset.",".$pageSize;
$ret = mysql_query($sql,$conn);
//echo $sql."<br/>";
while($list=mysql_fetch_array($ret)){
$row[] = $list;
}
mysql_close($conn);
return $row;
}
/**
* 统计总行数
*/
public function countAllRow(){
$dbconndb = new DBConnection();
$conn = $dbconndb->getConnection();
mysql_select_db("kalkun");
$sql="select count(1) from outbox ";
$ret=mysql_query($sql);
$row = mysql_fetch_array($ret);
mysql_close($conn);
return $row[0];
}
}
?>
//comm/dao/DBConnection.php
<?php
class DBConnection{
public static $dbname;
public static $dbaddr="localhost";
public static $dbName="root";
public static $dbpassword="sa";
public static $dbconInstance = null;
/**
* 得到连接
*/
public static function getConnection(){
return mysql_connect(DBConnection::$dbaddr,DBConnection::$dbName,DBConnection::$dbpassword);
}
/**
* 关闭连接
*/
public static function closeCon($link){
mysql_close($link);
}
}
?>
<?php
//pageBean.php 分页封装类
class pageBean {
private $allRow=0;//总行数
private $currentPage;//当前页
private $pageSize ;//每页显示行数
private $totalPage ;//总页数
private $dadalist = array();//存储数据集合
public function setDatalist($dadalist){
$this->dadalist=$dadalist;
}
public function getDatalist(){
//print_r($this->datalist);
return $this->dadalist;
}
public function setAllRow($allRow){
$this->allRow=$allRow;
}
public function getAllRow(){
return $this->allRow;
}
public function setCurrentPage($currentPage)
{
$this->currentPage=$currentPage;
}
public function getCurrentPage(){
return $this->currentPage;
}
public function setPageSize($pagesize){
$this->pageSize=$pagesize;
}
public function getPageSize(){
return $this->pageSize;
}
public function setTotalPage($totalPage){
$this->totalPage=$totalPage;
}
public function getTotalPage(){
return $this->totalPage;
}
/**
* 统计总页数
*/
static function countPage($pagesize, $countrow) {
//$pageCount= countrow()%$pagesize==0?(countrow()/$pagesize):((int)(countrow()/$pagesize)+1);
if ($countrow % $pagesize == 0) {
$pageCount = $countrow / $pagesize;
} else {
$pageCount = (int) ($countrow / $pagesize) + 1;
}
return $pageCount;
}
/**
* 计算当前指开始记录数
*/
static function countOffset($pagesize, $currentPage) {
return $pagesize * ($currentPage -1);
}
}
?>
//outboxbiz.php
<?php
/*
* Created on 2010-7-21
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
include_once("outboxdao.php");
include_once("../pageBean.php");
class outboxbiz{
public function getoutboxPageBean($currentPage,$pageSize){
$outboxdao = new outboxdao();
$dbconn = new DBConnection();
$offset = pageBean::countOffset($pageSize,$currentPage);//计算开始记录数
$allRow = $outboxdao->countAllRow();//得到总行数
$row = $outboxdao->getList($offset,$pageSize);//指定到数据
pageBean::countPage($pageSize,$allRow);//总页数
//print_r($row);
$pageBean = new pageBean();
$pageBean->setAllRow($allRow);
$pageBean->setPageSize($pageSize);
$pageBean->setCurrentPage($currentPage);
$pageBean->setDatalist($row);
$pageBean->setTotalPage(pageBean::countPage($pageSize,$allRow));
$datalist=$pageBean->getDatalist();
return $pageBean;
}
}
?>
//displayoutbox.php
<html>
<head>
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="PHPEclipse 1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>title</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">
<TABLE id=oTableHead border=1>
<TR>
<td class=Ibx_td_From>
ID
</td>
<td class=Ibx_td_From>
收信号码
</td>
<td class=Ibx_td_Subject>
主题
</td>
<td class=Ibx_td_Date>
日期
</td>
</TR>
<?php
include_once("outboxbiz.php");
include_once("../pageBean.php");
$outboxbiz=new outboxbiz();
$pageSize=10;
$page=$_GET["p"];
echo $page;
$currentPage=isset($page)?intval($page):1;
$pageBean = $outboxbiz->getoutboxPageBean($currentPage,$pageSize);
$currentPage=$pageBean->getCurrentPage();
$pageCount=$pageBean->getTotalPage();
//$row=$pageBean->datalist;//此处不明:pageBean 类中的定义私用变量。
//$row = array();
$row = $pageBean->getDatalist();//此处变量row得不到值。
foreach($row as $val){
echo "<tr><td>".$val["ID"]."</td><td>".$val["DestinationNumber"]."</td><td>".substr($val["TextDecoded"],0,10)."</td><td>".$val["InsertIntoDB"]."</td></tr>";
}?>
</table>
<table>
<tr>
<td>
<?php
$stringPage;
if($currentPage==1){
$stringPage.="首页 上页";
}else{
$stringPage.="<a href=?p=1>第一页</a>|<a href=?p=".($currentPage-1).">上一页</a>|";
}
if($currentPage==$pageCount || $pageCount==0){
$stringPage.="末页 下页";
}else
{
$stringPage.="<a href=?p=".$pageCount.">末页</a>|<a href=?p=".($currentPage+1).">下一页</a>|";
}
echo "<center>".$stringPage."</center>";
?>
</td>
</tr>
</table>
</body>
</html>