php 网页中的 page2 分页不起作用

有人可以帮我解决 php 网页的分页语法吗?我设置了一个分页代码,每页显示 20 条记录。记录根据“开始日期”显示和“结束日期”。

问题是,它可以在 第 1 页上运行,但是当我点击 第 2 页第 2 页时 a> 的值不会在 page2 上转发。$_POST['startdate'] 和 在分页中那么它就不起作用。我假设 $_POST['enddate]


白衣染霜花
浏览 142回答 3
3回答

杨__羊羊

$_POST处理 POST HTTP 请求时,PHP 会填充超级全局变量。第 1 页的请求就是这种情况。但是,您的 go2page() 函数正在发生变化location.href,它会生成 GET HTTP 请求,分页链接也会发生变化。您应该将 startdate 和 enddate 参数附加到分页 URL,以将您的参数转发到下一个/上一个请求:qm.php?page=<YOUR-PAGE-NUMBER>&startdate=<YOUR-START-DATE>&enddate=<YOUR-END-DATE>';并在处理 GET 请求时使用 $_GET['startdate'] 和 $_GET['enddate] 检索这些内容。

www说

添加$_POST内部链接的值并将其用作$_GET,这样您就可以同时使用这两个链接。$startdate1=$enddate1=null; //to hide noticeif(isset($_POST['Search'])){&nbsp; &nbsp; &nbsp; $startdate1 = $_POST['startdate'];&nbsp; &nbsp; &nbsp; echo "Start date :&nbsp; ".$startdate1.", ";&nbsp; &nbsp; &nbsp; $enddate1 = $_POST['enddate'];&nbsp; &nbsp; &nbsp; echo "End date :&nbsp; ".$enddate1;} else if (!empty($_GET['startdate']) && !empty($_GET['enddate'])){&nbsp; &nbsp; &nbsp; $startdate1 = $_GET['startdate'];&nbsp; &nbsp; &nbsp; echo "Start date :&nbsp; ".$startdate1.", ";&nbsp; &nbsp; &nbsp; $enddate1 = $_GET['enddate'];&nbsp; &nbsp; &nbsp; echo "End date :&nbsp; ".$enddate1;}$pagLink .= "<li><a href='qm.php?page=".($k+$i)."&startdate=".startdate1."&enddate=".$enddate1."'>".($k+$i)."</a></li>";根据您的需要:$pagLink = "";&nbsp;if($pn>=2){&nbsp;&nbsp; &nbsp; echo "<li><a href='qm.php?page=1&startdate=".startdate1."&enddate=".$enddate1."'> << </a></li>";&nbsp;&nbsp; &nbsp; echo "<li><a href='qm.php?page=".($pn-1)."&startdate=".startdate1."&enddate=".$enddate1."'> < </a></li>";&nbsp;}&nbsp;for ($i=-4; $i<=4; $i++) {&nbsp;&nbsp; if($k+$i==$pn)&nbsp;&nbsp; &nbsp; $pagLink .= "<li class='active'><a href='qm.php?page=".($k+$i)."&startdate=".startdate1."&enddate=".$enddate1."'>".($k+$i)."</a></li>";&nbsp;&nbsp; else&nbsp; &nbsp; $pagLink .= "<li><a href='qm.php?page=".($k+$i)."&startdate=".startdate1."&enddate=".$enddate1."'>".($k+$i)."</a></li>";&nbsp; &nbsp;};&nbsp; &nbsp;echo $pagLink;&nbsp;if($pn<$total_pages){&nbsp;&nbsp; &nbsp; echo "<li><a href='qm.php?page=".($pn+1)."&startdate=".startdate1."&enddate=".$enddate1."'> > </a></li>";&nbsp;&nbsp; &nbsp; echo "<li><a href='qm.php?page=".$total_pages."&startdate=".startdate1."&enddate=".$enddate1."'> >> </a></li>";&nbsp;}这将帮助您将日期移至下一页。您需要将其设置为所有分页链接。您还可以制作额外的 if 语句以不传递空GET编辑:正如我已经说过的:您需要将其设置为所有分页链接。您还可以制作额外的 if 语句以不传递空 GET (包括 javascript)function go2Page()&nbsp;{&nbsp;&nbsp; &nbsp; var pn = document.getElementById("pn").value;&nbsp;&nbsp; &nbsp; pn = ((pn><?php echo $total_pages; ?>)?<?php echo $total_pages; ?>:((pn<1)?1:pn));&nbsp;&nbsp; &nbsp; window.location.href = 'teztz.php?page='+pn+'&startdate=<?=startdate1;?>&enddate=<?=$enddate1;?>';}&nbsp;

Helenr

你的有一个错误isset($_POST['Search'])你的代码:if(isset($_POST['Search'])){&nbsp; &nbsp; $startdate1 = $_POST['startdate'];&nbsp; &nbsp; echo "Start date :&nbsp; ".$startdate1", ";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $enddate1 = $_POST['enddate'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "End date :&nbsp; ".$enddate1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }可能的工作解决方案:if(isset($_POST['Search'])){&nbsp; &nbsp; $startdate1 = $_POST['startdate'];&nbsp; &nbsp; echo "Start date :&nbsp; ".$startdate1.", ";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $enddate1 = $_POST['enddate'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "End date :&nbsp; ".$enddate1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }虽然我还没有尝试过,但我认为这就是原因,page2 中的分页将不起作用,因为在 page2 的分页错误之后代码不会执行。编辑:. 解决了问题。echo "Start date :&nbsp; ".$startdate1", ";不同于echo "Start date :&nbsp; ".$startdate1.", ";
打开App,查看更多内容
随时随地看视频慕课网APP