一个很奇怪的问题,有兴趣的能不能帮我找找原因。
我做了一个带分页分栏目功能的查询页面,主要代码如下:
<?
include("conn.inc.php");
include("function.php");
$perpage=20;
if($Submit=="查找"or!$offset){$offset=0;}
$query="select id,filename from ziyuan where filename like binary '%$file_name%'";
if($leixing_id&$leixing_id!="****文件类型****"){
$query=$query." and leixing_id=".$leixing_id;
}
$rows=mysql_query($query);
$all_rows=mysql_num_rows($rows);
$c_page=cut_page($all_rows,$perpage,$offset);
$query=$query." order by id DESC limit ". $offset.",".$perpage;
?>
……………………………
<td width="394" valign="top" background="26zhong.files/dian.gif"><table width="100%" border="0">
<tr>
<td>
<form name="form2" method="post" action="">
<table width="100%" border="0">
<tr>
<td>站内搜索:</td>
<td><input name="file_name" type="text" id="file_name" size="15" maxlength="50"></td>
<td>
<?
$query2="select * from ziyuan_leixing order by id";
$rows2=mysql_query($query2);
?>
<select name="leixing_id" size="1" id="leixing_id">
<option selected>****文件类型****</option>
<?
while($leixingrs=mysql_fetch_array($rows2)){
echo "<option value=".$leixingrs["id"].">".$leixingrs["ziyuan_leixingming"]."</option>";
}
?>
</select></td>
<td><input type="submit" name="Submit" value="查找"></td>
</tr>
</table>
</form></td>
</tr>
<tr>
<td><table width="100%" border="0">
<?
$rows=mysql_query($query);
if($rs=mysql_fetch_array($rows)){
do{
?>
<tr>
<td><img src="26zhong.files/go.gif" width="9" height="9"></td>
<td align="left"><?echo "<a href=wenjian.php?id=".$rs["id"].">".$rs["filename"]."</a>";?>
</td>
</tr>
<?}while($rs=mysql_fetch_array($rows));
}else{
echo "没有纪录可显示!";
}
?>
</table></td>
</tr>
<tr align="right">
<td colspan="2"> <table width="80%" border="0" cellspacing="0" cellpadding="2">
<?
if(!$leixing_id){
?>
<tr>
<td>共 <?echo $c_page[0];?> 页</td>
<td>第 <?echo $c_page[1];?> 页</td>
<td><a href="ziyuan.php?offset=0">首页</a></td>
<td><a href="ziyuan.php?offset=<?echo $c_page[2];?>">上一页</a></td>
<td><a href="ziyuan.php?offset=<?echo $c_page[3];?>">下一页</a></td>
<td><a href="ziyuan.php?offset=<?echo $c_page[4];?>">末页</a></td>
</tr>
<?
}else{
if($leixing_id!="****文件类型****"){
$templink="&leixing_id=".$leixing_id;
}else{
$templink="";
}
?>
<tr>
<td>共 <?echo $c_page[0];?> 页</td>
<td>第 <?echo $c_page[1];?> 页</td>
<td><a href="ziyuan.php?offset=0<?echo $templink;?>">首页</a></td>
<td><a href="ziyuan.php?offset=<?echo $c_page[2],$templink;?>">上一页</a></td>
<td><a href="ziyuan.php?offset=<?echo $c_page[3],$templink;?>">下一页</a></td>
<td><a href="ziyuan.php?offset=<?echo $c_page[4],$templink;?>">末页</a></td>
</tr>
<?
}
?>
</table></td>
</tr>
</table> </td>
………………………………
<?
mysql_close($conn);
?>
其中function.php的源代码为:
<?
//显示提示信息并返回到上一页
function back_msg($msg){
echo "<script language=javascript>";
echo "window.alert('".$msg."');";
echo "history.back();";
echo "</script>";
exit;
}
function replace($string){
$string=str_replace(chr(32)," ",$string);
$string=nl2br($string);
return $string;
}
function cut_page($all_rows,$perpage,$offset)
{
$all_page=ceil($all_rows/$perpage);
$now_page=ceil($offset/$perpage)+1;
$last_offset=$offset-$perpage;
if ($last_offset<0) $last_offset=$offset;
$next_offset=$offset+$perpage;
if ($next_offset>=$all_rows) $next_offset=$offset;
$finish_offset=($all_page-1)*$perpage;
return array($all_page,$now_page,$last_offset,$next_offset,$finish_offset);
}
?>
现在的问题是这样的,凡是leixing_id为1,3,5等奇数时,页面能正常的按栏目类型进行分页,但凡是leixing_id为2,4,6等偶数时,页面就不能正常的按栏目类型进行分页。我测试了好多遍都是这样,正在狂郁闷中,盼望着哪位高手能帮着解决一下。