日期:2014-05-17 浏览次数:20659 次
public static function getuser(CleanRequest &$clean){
Registry::set('clean',$clean);
//print_r(Registry::get('clean'));die();
//print_r(Registry::get());
$user=$clean->get('user');
if($user)
$where.=($where?' and':' where').' admin_name like \'%'.$user.'%\'';
$db=new MysqlDB();
$sql1="select * from admin";
$result=$db->query($sql1);
$count=$db->num_rows($result);
$pagesize=5;
if($page=$clean->get('page')){
$page = intval($page);
}
else {
$page=1;
}
$pagecount=ceil($count/$pagesize);
$limit=$page-1;
//if($where)
$sql="select * from admin ".$where." limit ".$limit*$pagesize.",$pagesize";
$r=$db->select($sql);
foreach($r as $v){
$html.='<tr><td>'.$v['admin_id'].'</td><td>'.$v['admin_name'].'</td><td>'.$v['admin_pwd'].'</td><td><a href="javascript:void(0)" class="del">删除</a></td></tr>';
}
/*for($i=1;$i<=$pagecount;$i++){//数字分页
if($i!=$page)
$html.=" <a href='/?r=User&index&page=".$i."'>$i</a>";
else
$html.=" ".$i;*/
//}
if($count>$pagesize){
/*if($page==1){//如果页数只有一页
$html .= '首页|上一页';
}*/
//else{
$html.='<tr><td colspan="5">';
if($page>1){
$html .= '<a href="/?r=User&action=index&page=1">首页</a>|<a href="/?r=User&action=index&page='.($page-1).'">上一页</a>|';
}
if($page==$pagecount||$pagecount==0){//如果当前页等于总也数
$html .= '下一页|尾页';
}
else{
$html .= '<a href="/?r=User&action=index&page='.($page+1).'">下一 页</a>|<a href="/?r=User&action=index&page='.$pagecount.'">尾页</a>';
}
}
$html.=' 共'.$count.'条记录 每页'.$pagesize.'条 共'.$pagecount.'页</td></tr>';
return $html;
}
------解决方案--------------------
5楼给的是很清楚的,用的面向对象的方法,我也给你一个我自己用的
<?php
require_once 'db.php';
session_start();
$pagesize = 5; // 每一页显示多少
$page = $_GET["page"];
if($page == ""){ //如果没有设定页数则默认为1
$page=1;
}
$sql = "select * from st_info order by ID desc limit ".($pagesize*($page-1)).",".$pagesize;
$query=mysql_query($sql); //显示从多少到多少
$quer2=mysql_query("select * from st_info");
$num=mysql_num_rows($quer2); //查找所有的行数
$pagecount=ceil($num/$pagesize); //应该显示多少页
if($pagecount == 0){
echo "sorry,it's null";
}else{
if(mysql_num_rows($query)==0){
echo "sorry,";
}
}
?>
<form name="tiaozhuanform">
<table width="760" align="center">
<tr>
<td>
总共有<?php echo $pagecount;?>页,
每页显示<?php echo $pagesize;?>条信息,
总共有<?php echo $num;?>条数据.
<select name="theselect" onchange="javascript:tiaozhuan(this.options[this.options.selectedIndex].value);">
<?php
for($i=1;$i<=$pagecount;$i++){
echo '<option value="' . $i . '"