$page=$_GET['页面'] 未从 URL 参数页面分配值。



我在接收和重新使用通过GET变量发送的变量时遇到问题。

URl-参数"page"未通过$_GET['page']赋值。GET未将任何值传递给$page vailable
没有分页链接创建是正确的,但当我点击它们时,帖子并没有改变,它只显示前两个帖子。但我的数据库由六个帖子组成,每页2个,平均3页。

<?php 
require_once('inc/header.php'); 
$no_of_posts = 2;
if(isset($_Get['page'])){
$page=$_Get['page'];
}
else{
$page=1;
}
$all_posts_query="SELECT * FROM posts WHERE status='publish'";
$all_posts_run=mysqli_query($conn,$all_posts_query);
$all_posts=mysqli_num_rows($all_posts_run);
$total_pages=ceil($all_posts / $no_of_posts); //ok its working for paging
echo $posts_start_from=(2-1)*$no_of_posts;//ok working start from recent to 
older id=2 start=2
?> 
<?php
}
$query="SELECT *FROM posts WHERE status='publish' ORDER BY id DESC LIMIT $posts_start_from,$no_of_posts";
$run=mysqli_query($conn,$query);
if(mysqli_num_rows($run)>0){
while($row=mysqli_fetch_array($run)){
$id=$row['id'];
$date=getdate($row['date']);
$day=$date['mday'];
$month=$date['month'];
$year=$date['year'];
$title=$row['title'];
$author=$row['author'];
$author_image=$row['author_image'];
$image=$row['image'];
$categories=$row['categories'];
$tags=$row['tags'];
$post_data=$row['post_data'];
$views=$row['views'];
$status=$row['status'];
?>

<nav class="pagi" >
<ul class="pagination justify-content-center mt-5">
<?php
for($i=1; $i<=$total_pages; $i++)
{
echo "<li class='page-item ".($page==$i ? 'active':'')."'><a class='page-link' href='index.php?page=".$i."'>$i</a></li>";
}
?>
</ul>
</nav>

Url链接工作正常,它来自$i变量。yryfchbcd cjdndjnn

更改

if ( isset($_Get['page']) ) {
$page = $_Get['page'];
}

if ( isset($_GET['page']) ) {
$page = $_GET['page'];
}

我建议使用具有良好语法检查器代码完成的编辑器或IDE。这样你就会更容易避免这样的错误。

最新更新