2017-06-19 2 views
0

Ich zeige Fotos aus der Datenbank.Paginierung zeigen Inhalt nicht von Isset-Methode

<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> 

ich verwende post-Methode

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

i auf die Schaltfläche klicken Sie auf Absenden dann zeigt es Bilder aus der ersten Abfrage ("SELECT * FROM new_photos WHERE Gewicht zwischen 10 und 15"), aber wenn ich Klicken Sie auf Seite 2 von Seitenumbruch laden Sie Inhalt von sonst (zweite Abfrage "SELECT * FROM new_phoos") -Methode.

Paginierung-Code mein 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 }} 

    ?> 
+0

Wollen Sie bitte geben Sie Ihren Code für Paginierung? –

+0

jetzt überprüfen Sie es .. –

Antwort

0

denn das ist, wenn Sie Form und post-Methode verwenden, dann per Post Variable in $_POST['submit'] einreichen, aber nach der von Ihnen verwendeten <a></a> Tag, das Ihre bedeuten haben keine $_POST['submit'] Variable, warum else Zustand läuft. Am besten können Sie URL-Parameter und $_GET wie verwenden.

In Form

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

Im Hinblick html

<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> 

In Paginieren

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>'; 
    } 
} 

prüfen $_POST['submit']null enthalten oder existieren, weil, wenn Ihr $_POST['submit'] null enthalten dann isset() wird ret Urne false, die sonst bedeuten beispielsweise ausführen: -

$array = ['key' => null]; 
var_dump($array['key']) // false #because key has null value 
var_dump($array['key1']) // false #key not exist 
+0

Ich habe Code aktualisiert wieder sehen –

+0

, aber Ihr Code macht keinen Sinn, Sie verwenden paginate, aber Sie sind nicht Daten durch Limit abrufen Limit –

+0

können Sie Ihre SQL zeigen, wo Sie Limit –