Php 分页不显示isset方法中的内容

Php 分页不显示isset方法中的内容,php,pagination,Php,Pagination,我正在显示数据库中的照片 <div class="col-md-10 bg col-md-push-2 "> <div class="align_center gallery"> <?php if(isset($_POST['submit'])){ include "anj.php"; $sql = 'SELECT * FROM new_phot

我正在显示数据库中的照片

<div class="col-md-10 bg col-md-push-2  ">
    <div class="align_center  gallery">
        <?php
            if(isset($_POST['submit'])){

                include "anj.php";

                $sql =  'SELECT * FROM new_photos WHERE weight BETWEEN 10 AND 15';
                // function anjaan has code for showing images
                anjaan($sql);
            }else{

                include "anj.php";
                $sql='select * from new_photos';
                anjaan($sql);

            }
        ?>
    </div>
    <div class="  align_center ">
        <div class=" col-md-12 pagination gallery">
            <?php    
            echo $paginationctrl;
            ?>
        </div>
    </div>
</div>

我用的是post方法

<form method="post" action="index.php">
    <input type="Submit" name="submit" value="submit">
</form>

我点击submit按钮,然后它会显示第一次查询的图像(“从新照片中选择*,其中权重在10到15之间”),但当我点击pagination第2页时,它会从else(第二次查询“从新照片中选择*)方法加载内容

分页代码 我的anj.php

<?php
 function anjaan($sql ){
 include 'database.php';
 function make_thumb($src, $dest, $desired_width) {

    /* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);

/* find the "desired height" of this thumbnail, relative to the desired 
width  */
$desired_height = floor($height * ($desired_width / $width));

/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);

/* copy source image at a resized size */
 imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, 
 $desired_width, $desired_height, $width, $height);

    /* create the physical thumbnail image to its destination */
    imagejpeg($virtual_image, $dest);
 }
$sql  ;
$query = mysqli_query($db,"$sql" );
$row  = mysqli_num_rows($query);
$rows =$row[0];
$page_rows=8;
$last=ceil($row/$page_rows);
if($last<1){
     $last= 1;
}
 $pagenum=1;
if(isset($_GET['pn'])){
    $pagenum = (int) $_GET['pn'];
}

if($pagenum<1){
     $pagenum=1;
}
else if($pagenum>$last){
     $pagenum=$last;
}

 $limit='LIMIT' .($pagenum-1) * $page_rows.','.$page_rows;
$n=($pagenum-1) * $page_rows;
 $sql1  = "  $sql LIMIT $n ,$page_rows";
  $query = mysqli_query($db,$sql1 );
  global $paginationctrl;
  $paginationctrl='';
 if($last !=1){

     if($pagenum>1){
              $previous = $pagenum-1;
              $paginationctrl .='<a  href="'.$_SERVER['PHP_SELF'].'?
pn='.$previous.'">Pr</a>'.'&nbsp;';
              for($i = $pagenum-3 ;$i<$pagenum;$i++){
                       if($i>0){
                                $paginationctrl .='<a  class="active" 
href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a>'.'&nbsp;';
                       }
              }
     }

    $paginationctrl .=''.$pagenum.'&nbsp;'  ;
        for($i = $pagenum+1 ;$i<$last;$i++){
                 $paginationctrl .='<a  class="active" 
   href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a>'.'&nbsp;';
                       if($i>=$pagenum+4){
                                break;
                       }
              }
      if($pagenum != $last){
              $next =$pagenum+1;
             $paginationctrl .=' <a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">Next</a>';
     }
 }
  while($row = mysqli_fetch_array($query,MYSQLI_ASSOC)){
  $r=$row['path'];
     $id=$row['weight'];
  $image = "new_photos/".$row['path'];
 $image1 = "images/thumb/".$row['path'];
$path = 'images/thumb/'.$r;
$thumb =  make_thumb($image, $path,1000);
  ?>
<a  class="fancybox col-md-6" href="<?php echo $image; ?>" data-
 fancybox="image"    >

 <img class =  " galleryimage" src= "<?php echo $image1; ?>" >
<p class=" align_center"><?php echo $id; ?> gm</p>
 </a>

 <?php }}

     ?>

这是因为当您使用form and post方法时,它会在
$\u post['submit']
中发布提交变量,但在您使用
标记之后,这意味着您没有
$\u post['submit']
变量,这就是为什么
else
条件正在运行的原因。您最好使用url参数和
$\u GET

形式上

<form method="post" action="index.php?sort=weight">
    <input type="Submit" name="submit" value="submit">
</form>

请您提供分页代码好吗?现在检查一下。但是您的代码没有任何意义您正在使用分页,但您没有通过限制使用限制获取数据为什么要使用
$\u POST['submit']
如果有自然照片,那么如果用户单击仅显示河流照片,则仅显示河流照片更新了答案,您可以这样尝试读取代码中使用的每个变量。我使用了新变量
sort=weight
您可以使用任何您喜欢的变量。我不想编辑anj.php,因为有很多类别和我的按钮具有不同的排序类型
<div class="col-md-10 bg col-md-push-2  ">
    <div class="align_center  gallery">
        <?php
            if(isset($_GET['sort']) && $_GET['sort'] == 'weight'){

                include "anj.php";

                $sql =  'SELECT * FROM new_photos WHERE weight BETWEEN 10 AND 15';
                // function anjaan has code for showing images
                anjaan($sql);
            }else{

                include "anj.php";
                $sql='select * from new_photos';
                anjaan($sql);

            }
        ?>
    </div>
    <div class="  align_center ">
        <div class=" col-md-12 pagination gallery">
            <?php    
            echo $paginationctrl;
            ?>
        </div>
    </div>
</div>
if($last !=1){

     if($pagenum>1){
              $previous = $pagenum-1;
              $paginationctrl .='<a  href="'.$_SERVER['PHP_SELF'].'?
sort=weight&pn='.$previous.'">Pr</a>'.'&nbsp;';
              for($i = $pagenum-3 ;$i<$pagenum;$i++){
                       if($i>0){
                                $paginationctrl .='<a  class="active" 
href="'.$_SERVER['PHP_SELF'].'?sort=weight&pn='.$i.'">'.$i.'</a>'.'&nbsp;';
                       }
              }
     }

    $paginationctrl .=''.$pagenum.'&nbsp;'  ;
        for($i = $pagenum+1 ;$i<$last;$i++){
                 $paginationctrl .='<a  class="active" 
   href="'.$_SERVER['PHP_SELF'].'?sort=weight&pn='.$i.'">'.$i.'</a>'.'&nbsp;';
                       if($i>=$pagenum+4){
                                break;
                       }
              }
      if($pagenum != $last){
              $next =$pagenum+1;
             $paginationctrl .=' <a href="'.$_SERVER['PHP_SELF'].'?sort=weight&pn='.$next.'">Next</a>';
     }
 }
$array = ['key' => null];
var_dump($array['key']) // false #because key has null value 
var_dump($array['key1']) // false #key not exist