★★★★分页技术★★★★
下面是源代码,我的问题是,当我查询的时候,比如我查询用户级别,出来的结果有几页的时候,我点击下一页或者填入要跳转的页面的时候,跳转的结果不是查询结果的下一页,而是所有用户列表的下一页,怎么解决这个问题??
救命!!
<TABLE cellSpacing=1 cellPadding=2 width="100%" align=center bgColor=#000000 border=0>
<tr>
<td colspan="6" align="center" bgcolor="#00CCFF"> 用户管理</td>
</tr>
<form name="form1" method="post" action="<? $PHP_SELF ?>">
<tr>
<td colspan="6" align="center" bgcolor="#00CCFF">
用户查询
<select name="select">
<option selected>请选择查询方式</option>
<option value="user_name">用户名</option>
<option value="user_addr">所在校区</option>
<option value="user_class">用户级别</option>
</select>
<input name="user_query" type="text" id="user_query" value="请填入相应的关键字">
<input type="submit" name="Submit" value="查询">
</td>
</tr>
</form>
<?
include("../connect.php");
if($_POST[select]&&$_POST[select]!="请选择查询方式"&&$_POST[user_query]!="请填入相应的关键字")
{
$sql=mysql_query("select * from lug_user where $_POST[select]=\"$_POST[user_query]\"");
$user_sum=mysql_num_rows($sql);
if(empty($_GET[offset]))
{
$_GET[offset]=0;
}
$pg_sum=ceil($user_sum/1); //总页数;
$endoffset=$pg_sum*1-1;
if(isset($_POST[jump]))
{
if($_POST[jump]<=$pg_sum)
{
$jumpto=$_POST[jump]*1-1;
$_GET[offset]=$jumpto;
}
else
{
$_GET[offset]=$endoffset;
}
}
$query=mysql_query("select * from lug_user where $_POST[select]='$_POST[user_query]' order by user_id desc limit $_GET[offset],1");
echo'
<tr>
<td colspan="6" bgcolor="#FFFFFF"><div align="center">共查询到<font color=red>'.$user_sum.'</font>位用户符合条件</div></td>
</tr>
<tr>
<td bgcolor="#00CCFF" width="12%">用户id</td>
<td bgcolor="#00CCFF" width="20%">用户名</td>
<td bgcolor="#00CCFF" width="17%">所在校区</td>
<td bgcolor="#00CCFF" width="17%">用户级别</td>
<td bgcolor="#00CCFF" width="17%">修改</td>
<td bgcolor="#00CCFF" width="17%">删除</td>
</tr>';
while($array=mysql_fetch_array($query))
{
echo'
<tr>
<td bgcolor="#FFFFFF" width="12%">'.$array[user_id].'</td>
<td bgcolor="#FFFFFF" width="20%"><a href=user_edit.php?id='.$array[user_id].'&&act=query>'.$array[user_name].'</a></td>
<td bgcolor="#FFFFFF" width="17%">'.$array[user_addr].'</td>
<td bgcolor="#FFFFFF" width="17%">'.$array[user_class].'</td>
<td bgcolor="#FFFFFF" width="17%"><a href=user_edit.php?id='.$array[user_id].'&&act=update>修改</a></td>
<td bgcolor="#FFFFFF" width="17%"><a href=user_edit.php?id='.$array[user_id].'&&act=del>删除</a></td>';
}
?>
</tr>
<tr>
<td height="27" colspan="6" bgcolor="#FFFFFF"> </td>
</tr>
<form name="form2" method="post" action="<? $PHP_SELF ?>">
<tr align="center" bgcolor="#00CCFF">
<td colspan="6"> <a href="<? $PHP_SELF ?> ?offset=0">首页 </a> <a href="<? $PHP_SELF ?> ?offset=<? echo $endoffset ?>">尾页
</a>
<?
if($_GET[offset])
{
$preoffset=$_GET[offset]-1;
echo"<a href='$PHP_SELF?offset=$preoffset'>上一页<a>";
}
if($pg_sum!=0&&(($_GET[offset]+1)/1)!=$pg_sum)
{
$nextoffset=$_GET[offset]+1;
echo"<a href='$PHP_SELF?offset=$nextoffset'>下一页<a>";
}
$pg_no=$_GET[offset]/1+1;
?>
页次:<? echo" <font color=red>$pg_no</font>/$pg_sum";?> 转到第
<input name="jump" type="text" id="jump" size="3">
页
<input type="submit" name="Submit2" value="GO"> </td>
</tr>
</form>
</table>
<?
}
else{
$sql=mysql_query("select * from lug_user");
$user_sum=mysql_num_rows($sql);
if(empty($_GET[offset]))
{
$_GET[offset]=0;
}
$pg_sum=ceil($user_sum/1); //总页数;
$endoffset=$pg_sum*1-1;
if(isset($_POST[jump]))
{
if($_POST[jump]<=$pg_sum)
{
$jumpto=$_POST[jump]*1-1;
$_GET[offset]=$jumpto;
}
else
{
$_GET[offset]=$endoffset;
}
}
$query=mysql_query("select * from lug_user order by user_id desc limit $_GET[offset],1");
echo'
<tr>
<td colspan="6" bgcolor="#FFFFFF"><div align="center">共有<font color=red>'.$user_sum.'</font>位用户</div></td>
</tr>
<tr>
<td bgcolor="#00CCFF" width="12%">用户id</td>
<td bgcolor="#00CCFF" width="20%">用户名</td>
<td bgcolor="#00CCFF" width="17%">所在校区</td>
<td bgcolor="#00CCFF" width="17%">用户级别</td>
<td bgcolor="#00CCFF" width="17%">修改</td>
<td bgcolor="#00CCFF" width="17%">删除</td>
</tr>';
while($array=mysql_fetch_array($query)){
echo'
<tr>
<td bgcolor="#FFFFFF" width="12%">'.$array[user_id].'</td>
<td bgcolor="#FFFFFF" width="20%"><a href=user_edit.php?id='.$array[user_id].'&&act=query>'.$array[user_name].'</a></td>
<td bgcolor="#FFFFFF" width="17%">'.$array[user_addr].'</td>
<td bgcolor="#FFFFFF" width="17%">'.$array[user_class].'</td>
<td bgcolor="#FFFFFF" width="17%"><a href=user_edit.php?id='.$array[user_id].'&&act=update>修改</a></td>
<td bgcolor="#FFFFFF" width="17%"><a href=user_edit.php?id='.$array[user_id].'&&act=del>删除</a></td>'; }
?>
</tr>
<tr>
<td height="27" colspan="6" bgcolor="#FFFFFF"> </td>
</tr>
<form name="form2" method="post" action="<? $PHP_SELF ?>">
<tr align="center" bgcolor="#00CCFF">
<td colspan="6"> <a href="<? $PHP_SELF ?> ?offset=0">首页 </a> <a href="<? $PHP_SELF ?> ?offset=<? echo $endoffset ?>">尾页
</a>
<?
if($_GET[offset])
{
$preoffset=$_GET[offset]-1;
echo"<a href='$PHP_SELF?offset=$preoffset'>上一页<a>";
}
if($pg_sum!=0&&(($_GET[offset]+1)/1)!=$pg_sum)
{
$nextoffset=$_GET[offset]+1;
echo"<a href='$PHP_SELF?offset=$nextoffset'>下一页<a>";
}
$pg_no=$_GET[offset]/1+1;
?>
页次:<? echo" <font color=red>$pg_no</font>/$pg_sum";?> 转到第
<input name="jump" type="text" id="jump" size="3">
页
<input type="submit" name="Submit2" value="GO"> </td>
</tr>
</form>
</table>
<? }?>