您的代码中有几个问题。
第一的:
您使用的$_GET
变量不正确。您有$_GET{'page'}
,但您应该使用与$_POST
变量相同的方式,如下所示:$_GET['page']
第二:
您正在解释“发布”的概念,并错误地单击了链接。您需要使用下一个和上一个按钮进行的??操作是一个隐藏的表单,其中包含您需要的所有其他变量。例如,最简单的方法无需更改许多其他代码:
if( $page > 0 & $left_rec > $rec_limit)
{
$last = $page - 2;
// PrevIoUs button form
echo "<form action='?page=$last' method='POST'>";
echo "<input type='hidden' name='q' value='" . $_POST['q'] . "' />"; // This will be a field that saves information but won't appear on the page (though a user Could see it if they view source)
echo "<input type='submit' value='PrevIoUs Records' />";
echo "</form>";
echo " | "; // The delimiting character you were using, you'll need to style the input type='submit's to look more like a link if that's what you are going for
// Next button form
echo "<form action='?page=$page' method='POST'>";
echo "<input type='hidden' name='q' value='" . $_POST['q'] . "' />"; // This will be a field that saves information but won't appear on the page (though a user Could see it if they view source)
echo "<input type='submit' value='Next Records' />";
echo "</form>";
}
此方法会将您的变量保留在请求中。使用链接实际上会重置$ _POST变量。还有很多其他可能的解决方案,但这是修改示例所需的工作量最少的解决方案。