我已经下载了分页代码,并在我的本地机器上运行的网站中使用。在修改和测试后,我得到了更好的结果,但是有一个问题,它无法识别变量$ page。请参考以下代码:
<?php
$rpp = 3; // results per page
$adjacents = 4;
$page = intval($_GET["page"]);
if($page<=0) $page = 1;
$reload = $_SERVER['PHP_SELF'];
$sql = "SELECT * FROM ".TABLE_IMAGE." ORDER BY id ASC";
$qry = mysql_query($sql, $con);
// count total number of appropriate listings:
$tcount = mysql_num_rows($qry);
// count number of pages:
$tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number
$i = 1;
$count = 0;
$j = ($page-1)*$rpp;
while(($result = mysql_fetch_array($qry)) && (($count<$rpp) && ($j<$tcount))){
$id = $result['id'];
$img = $result['path'];
$title = $result['title'];
$detail = $result['detail'];
$priority = $result['priority'];
$active = $result['isActive'];
?>
<div id="block-image-slider" class="<?php echo(($i%2==0)?'even':'odd')?>">
<h2><?php echo $title ?></h2><span class="operation">[<a href="?action=edit§ion=slider&id=<?php echo $id ?>">កែប្រែ</a>|<a href="?action=delete§ion=slider&id='<?php echo $id ?>'">លុប</a>]</span>
<div class="block-slider-image-body">
<div class="left">
<ul>
<li>លេខរៀងទី<span class="space"><?php echo $id ?></span></li>
<li>កំនត់អទិភាពទី<span class="space"><?php echo $priority ?></span></li>
<li>ត្រូវបានបង្ហាញអោយឃើញ<span class="space"><?php echo (($active==1)?'បង្ហាញ':'មិនបង្ហាញ')?></span></li>
<li>អត្ថបទពេញ<div class="detail"><?php echo $detail ?></div></li>
</ul>
</div>
<div class="right">
<img src="<?php echo '../../image/Slider/'.$img ?>" alt="<?php echo $title ?>" width="170" height="100" />
</div>
<div style="clear:both;"></div>
</div>
</div>
<?php
mysql_data_seek($qry,$j);
$i++;
$j++;
$count++;
}//end of while loop
include("../include/paginate.php");
echo paginate_three($reload, $page, $tpages, $adjacents);
?>
这是它产生的错误:
Notice: Undefined index: page in C:\wamp\www\1. Chirst Joy Church Website\common\admin\index.php on line 87
我不知道如何修改更多。很高兴得到帮助。谢谢你。
答案 0 :(得分:2)
除非您的网址以?page=3
结尾(其中3表示当前页码),否则无效。为了解决这个问题,你应该改变这一行
$page = intval($_GET["page"]);
到
$page = (!empty($_GET["page"]) ? intval($_GET["page"]) : 1);