分页问题提问(急) 我从数据库中选择一部分来分页怎么不能分啊?比如说我把数据库中性别为男的选出来,然后对男的数据集来分页和全部数据集一起一起分页有区别吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 能说的清楚点吗。具体的哪些参数要变更啊! //设定每一页显示的记录数 $pagesize=10; //取得记录总数,计算总页数用 $sql0="select count(*) from yuangong where xb='$info'"; $res=mysql_query($sql0); $row0 = mysql_fetch_row($res); $numrows=$row0[0]; //计算总页数 $pages=ceil($numrows/$pagesize); //判断页数设置与否,如无则定义为首页 if (!isset($page)) $page=1; //判断转到页数 if (isset($ys)) if ($ys>$pages) $page=$pages; else $page=$ys; //计算记录偏移量 $offset=$pagesize*($page-1); //$sql="select count(*) from yuangong where xb='$info' "; //$result=mysql_query($sql); //$row=mysql_fetch_row($result); //if($row[0]==0){ //echo"<body bgcolor=#000000><center><font color=red>找不到相关的信息,请确认!!!</font></center></body>"; //exit(); // } echo"性别为 $info 的人数有:$row0[0] 人"; $xb=$info; echo"$pages"; $sql="select gh,xm,xb,csny,xl,zc,szbm,zw,bz from yuangong where xb='$xb'order by gh asc limit $offset,$pagesize"; $result=mysql_query($sql); echo"<center>"; echo"<table border=3 bordercolor=red width=100% > \n"; echo"<tr>"; // echo"<td width=35><center>序号</center></td>"; echo"<td><center>工号</center></td>"; echo"<td><center>姓名</center></td>"; echo"<td><center>性别</center></td>"; echo"<td><center>出生年月</center></td>"; echo"<td><center>学历</center></td>"; echo"<td><center>职称</center></td>"; echo"<td><center>所在部门</center></td>"; echo"<td><center>职务</center></td>"; echo"<td><center>备注</center></td>"; echo"</tr>"; while($row=mysql_fetch_row($result)) { echo"<tr>"; foreach($row as $value) { echo"<td>$value</td>"; } echo"</tr>"; } echo"</table>"; echo"</center>"; echo "<div align='center'><font size=2>共有".$pages."页(".$page."/".$pages.")</font><br>"; echo"<center>"; echo "<form action='count1.php' method='post'> "; //计算首页、上一页、下一页、尾页的页数值 $first=1; $prev=$page-1; $next=$page+1; $last=$pages; if ($page>1) { echo "<a href='count1.php?page=".$first."'><font size=2>首页</font></a> "; echo "<a href='count1.php?page=".$prev."'><font size=2>上一页</font></a> "; } if ($page<$pages) { echo "<a href='count1.php?page=".$next."'><font size=2>下一页</font></a> "; echo "<a href='count1.php?page=".$last."'><font size=2>尾页</font></a> "; } echo "</form>"; echo"</center>"; //分页——获得页数 function GetPageCount( $table , $pagesize , $where=null ) { $pagecount=""; $amount = $this -> GetCount( $table , $where ); if($amount) { if( $amount < $pagesize ) { $pagecount = 1; } if( $amount % $pagesize) { $pagecount = (int)( $amount / $pagesize) + 1; } else { $pagecount = $amount / $pagesize; } } else { $pagecount = 0; } if( $page > $pagecount ) { if( $pagecount == 0 ) { $page = 1; } else { $page = $pagecount + 1; } } Return $pagecount; } //分页——获得列表信息 function Page( $what , $table , $page , $pagesize , $where=null ) { Return $this -> SelectDb( $what , $table ,$where. " order by id desc limit ". ($page-1) * $pagesize. "," .$pagesize ); }我是为了特殊需要才写成两个函数的,也可以合并成一个函数,第一个函数获得总页数,第二个函数进行分页,获得数据里面用到$amount = $this -> GetCount( $table , $where );是获得符合条件记录的数量的,可以根据你的需要替换成普通的sql语句,如select count(id) from ...where...$this -> SelectDb()函数是普通的查询函数,可以根据你的需要替换成select ... from ... where ... order by ... limit ....$what:是要查询的字段$table:是要查询的表$page:要查询哪页的信息$pagesize:每页显示多少条$where:查询条件希望能帮到你 strrpos查找字符串结果出错,请教 请大家推荐一款“小而精”的blog系统,PHP+MYSQl的,谢谢 怎么把网站从一个服务器转到另一个服务器啊 switch语句的几个疑问 PHP处理登录问题 大家推荐一个windows下好用的php编辑器,谢谢![ Sybase的Text字段在PHP中被截断,急! 如果得到这样的结果!! 请问php如何连接Oracle数据库 求助! linux下让apache支持PHP配置问题 新手求救
//设定每一页显示的记录数
$pagesize=10;
//取得记录总数,计算总页数用
$sql0="select count(*) from yuangong where xb='$info'";
$res=mysql_query($sql0);
$row0 = mysql_fetch_row($res);
$numrows=$row0[0];
//计算总页数
$pages=ceil($numrows/$pagesize);
//判断页数设置与否,如无则定义为首页
if (!isset($page))
$page=1;
//判断转到页数
if (isset($ys))
if ($ys>$pages)
$page=$pages;
else
$page=$ys;
//计算记录偏移量
$offset=$pagesize*($page-1);
//$sql="select count(*) from yuangong where xb='$info' ";
//$result=mysql_query($sql);
//$row=mysql_fetch_row($result);
//if($row[0]==0){
//echo"<body bgcolor=#000000><center><font color=red>找不到相关的信息,请确认!!!</font></center></body>";
//exit();
// }
echo"性别为 $info 的人数有:$row0[0] 人";
$xb=$info;
echo"$pages";
$sql="select gh,xm,xb,csny,xl,zc,szbm,zw,bz from yuangong where xb='$xb'order by gh asc limit $offset,$pagesize";
$result=mysql_query($sql);
echo"<center>";
echo"<table border=3 bordercolor=red width=100% > \n";
echo"<tr>";
// echo"<td width=35><center>序号</center></td>";
echo"<td><center>工号</center></td>";
echo"<td><center>姓名</center></td>";
echo"<td><center>性别</center></td>";
echo"<td><center>出生年月</center></td>";
echo"<td><center>学历</center></td>";
echo"<td><center>职称</center></td>";
echo"<td><center>所在部门</center></td>";
echo"<td><center>职务</center></td>";
echo"<td><center>备注</center></td>";
echo"</tr>";
while($row=mysql_fetch_row($result))
{
echo"<tr>";
foreach($row as $value)
{
echo"<td>$value</td>";
}
echo"</tr>";
}
echo"</table>";
echo"</center>";
echo "<div align='center'><font size=2>共有".$pages."页(".$page."/".$pages.")
</font><br>";
echo"<center>";
echo "<form action='count1.php' method='post'> ";
//计算首页、上一页、下一页、尾页的页数值
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo "<a href='count1.php?page=".$first."'><font size=2>首页</font></a> ";
echo "<a href='count1.php?page=".$prev."'><font size=2>上一页</font></a> ";
}
if ($page<$pages)
{
echo "<a href='count1.php?page=".$next."'><font size=2>下一页</font></a> ";
echo "<a href='count1.php?page=".$last."'><font size=2>尾页</font></a> ";
}
echo "</form>";
echo"</center>";
function GetPageCount( $table , $pagesize , $where=null )
{
$pagecount="";
$amount = $this -> GetCount( $table , $where );
if($amount)
{
if( $amount < $pagesize )
{
$pagecount = 1;
}
if( $amount % $pagesize)
{
$pagecount = (int)( $amount / $pagesize) + 1;
}
else
{
$pagecount = $amount / $pagesize;
}
}
else
{
$pagecount = 0;
}
if( $page > $pagecount )
{
if( $pagecount == 0 )
{
$page = 1;
}
else
{
$page = $pagecount + 1;
}
}
Return $pagecount;
}
//分页——获得列表信息
function Page( $what , $table , $page , $pagesize , $where=null )
{
Return $this -> SelectDb( $what , $table ,$where. " order by id desc limit ". ($page-1) * $pagesize. "," .$pagesize );
}我是为了特殊需要才写成两个函数的,也可以合并成一个函数,第一个函数获得总页数,第二个函数进行分页,获得数据里面用到$amount = $this -> GetCount( $table , $where );是获得符合条件记录的数量的,可以根据你的需要替换成普通的sql语句,如select count(id) from ...where...
$this -> SelectDb()函数是普通的查询函数,可以根据你的需要替换成select ... from ... where ... order by ... limit ....$what:是要查询的字段
$table:是要查询的表
$page:要查询哪页的信息
$pagesize:每页显示多少条
$where:查询条件
希望能帮到你