Php 分页脚本错误--为什么要跳回第一页?
PHP学习者。下面的分页脚本似乎通常可以正常工作,但问题是,在20条记录的每一页上,当我选择一些行(通过复选框)并单击SUBMIT按钮时,20条记录的显示跳回第1页。行被选中没有问题,但我不明白为什么它会返回到第1页 在下面的脚本中问题是否明显?谢谢Php 分页脚本错误--为什么要跳回第一页?,php,mysql,pagination,Php,Mysql,Pagination,PHP学习者。下面的分页脚本似乎通常可以正常工作,但问题是,在20条记录的每一页上,当我选择一些行(通过复选框)并单击SUBMIT按钮时,20条记录的显示跳回第1页。行被选中没有问题,但我不明白为什么它会返回到第1页 在下面的脚本中问题是否明显?谢谢 //-----------------| // Add pagination. //-----------------| $nAdjacentPages = 3; // If the current page number is great
//-----------------|
// Add pagination.
//-----------------|
$nAdjacentPages = 3;
// If the current page number is greater than 1, then display:
// "<<" and "<" (i.e., << < ).
if ($nCurrentPage > 1)
{
echo " <a href =
'{$_SERVER['PHP_SELF']}?nCurrentPage=1'> << </a> " ;
$nPreviousPage = $nCurrentPage - 1 ;
echo " <a href =
'{$_SERVER['PHP_SELF']}?nCurrentPage=$nPreviousPage'> < </a> ";
}
// Appearance of page links when viewing page 5:
// << < 2 3 4 [5] 6 7 8 > >>
for ( $x = ( $nCurrentPage - $nAdjacentPages ) ;
$x < ( ( $nCurrentPage + $nAdjacentPages ) + 1 ) ;
$x++ )
{
// if it's a valid page number...
if ( ( $x > 0 ) and ( $x <= $nTotalPages ) )
{
// If on current page, 'highlight' but do not link.
// If not current page, make it a link.
if ( $x == $nCurrentPage )
{
echo " [<b> $x </b>] " ;
}
else
{
echo " <a href=
'{$_SERVER['PHP_SELF']}?nCurrentPage=$x'> $x </a> " ;
}
}
}
// If not last page, show '>' and '>>' links.
if ( $nCurrentPage != $nTotalPages )
{
$nNextPage = $nCurrentPage + 1;
echo " <a href =
'{$_SERVER['PHP_SELF']}?nCurrentPage=$nNextPage'> > </a> ";
echo " <a href =
'{$_SERVER['PHP_SELF']}?nCurrentPage=$nTotalPages'> >> </a> ";
}
?>
//-----------------|
//添加分页。
//-----------------|
$nAdjacentPages=3;
//如果当前页码大于1,则显示:
//“包含提交按钮和复选框的表单需要包含一个隐藏的输入,该输入给出nCurrentPage变量的当前值。它跳回到第1页,因为表单的操作
可能只是script.php
如果表单使用了GET
方法,则向表单中添加一个名为nCurrentPage
的隐藏字段,该字段具有当前页面的正确值
如果您的表单使用POST
方法,则将?nCurrentPage=$nCurrentPage
(或任何…)添加到表单操作
(例如,使其成为script.php?nCurrentPage=3
),或者使用上面的隐藏字段方法,并将此脚本更改为除了它似乎已经执行的$\u GET
之外,还可以检查$\u POST
。您可以发布表单的HTML吗?这将有助于确定它返回到第1页的原因。好的,谢谢!看起来这样就可以了!谢谢审阅。