2016-08-29 1 views
0

Ich habe drei get Parameter in PHP mysqli Ich muss zuerst die Daten speichern und dann die Daten und danach in listview anzeigen, aber ich möchte Listenansicht in Paginierung mit Limit 3 anzeigen .... Bitte helfen me.I in php bin hier ...Paginierung in PHP mit drei Parameter in Methoden erhalten

register.php

<?php 
include_once 'DB_Connect.php'; 

if (isset($_GET['finder'])) { 
    $name = $_GET['name']; 
    $ph = $_GET['phno']; 
    $date = date('Y-m-d'); 

    mysqli_query($con, "INSERT INTO donee (name,ph_no,pincode,time,blood_gp,upload_time) VALUES ('$name','$ph','$pin','$time','$blgp','$date')"); 
    if (!mysqli_error($con)) { 
     echo '<script>alert("Success...Registertion is Successfully.."); </script>'; 
    } else { 
     echo '<script>alert("Error...Your Registration is not Successfully..");</script> '; 
    } 
} 

searchdata.php

<?php 
    $blgp = $_GET['blgp']; 
    $time = $_GET['timing']; 
    $pin = $_GET['pin']; 
    $result = mysqli_query($con, "SELECT * FROM doner WHERE pincode='$pin' AND timing='$time' AND blood_gp='$blgp'"); 
    $rows = mysqli_num_rows($result); 
     if ($rows > 0) { 
      while ($post = mysqli_fetch_assoc($result)) { 
      echo $post['doner_id']; 
      echo $post["file"]; 
      echo $post["name"]; 
      echo $post["ph_no"]; 
      echo $post["blood_gp"]; 
      } 
     } else { 
      <h3>No Donors are Available</h3>; 
     } 
    ?> 
+0

2 neue Parameter hinzufügen $ _GET [ 'Offset'] und $ _GET [ 'Grenze'] in searchdata.php als in Abfrage http://www.w3schools.com/php/php_mysql_select_limit Ihre Suche begrenzen. asp –

+0

Und sanieren Sie Ihre Eingaben ... Ihr Code, wie er steht, ist anfällig für SQL-Injektion. – mituw16

+0

@KapitulaAlexey: verlinken Sie nicht zu w3fools. ihr Code ist Mist und voller schlechter Programmiermethoden. Verlinke stattdessen mit den offiziellen offiziellen Dokumenten von PHP oder Mysql. oder noch besser, eine andere Antwort auf dieser Seite. Dies ist im Grunde eine Täuschung von "wie paginieren", und es gibt viele Milliarden von Beispielen auf der Website. –

Antwort

0
.pagination_section { 
    float: left; 
    margin-top: 10px; 
    text-align: center; 
    width: 100%; 
} 
.pagination { 
    height: 40px; 
    margin: 20px 0; 
} 
.pagination ul { 
    border-radius: 3px; 
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); 
    display: inline-block; 
    margin-bottom: 0; 
    margin-left: 0; 
} 
.pagination ul li { 
    display: inline; 
} 
.pagination li:first-child a, .pagination li:first-child span, .pagination li a { 
    border-left-width: 1px; 
    border-radius: 3px 0 0 3px; 
    color: #3281ae; 
    font-weight: 800; 
} 
.pagination a, .pagination span { 
    -moz-border-bottom-colors: none; 
    -moz-border-left-colors: none; 
    -moz-border-right-colors: none; 
    -moz-border-top-colors: none; 
    background-color: #fff; 
    border-color: #ddd; 
    border-image: none; 
    border-style: solid; 
    border-width: 1px 1px 1px 0; 
    float: left; 
    line-height: 38px; 
    padding: 0 14px; 
    text-decoration: none; 
} 
.pagination .active a, .pagination .active span { 
    color: #999; 
    cursor: default; 
} 
.pagination a:hover, .pagination .active a, .pagination .active span { 
    background-color: #f5f5f5; 
} 
<?php 
function paginate($reload, $page, $tpages) { 
    $adjacents = 2; 
    $prevlabel = "&lsaquo; Prev"; 
    $nextlabel = "Next &rsaquo;"; 
    $out = ""; 
    // previous 
    if ($page == 1) { 
     $out.= "<span>" . $prevlabel . "</span>\n"; 
    } elseif ($page == 2) { 
     $out.= "<li><a href=\"" . $reload . "\">" . $prevlabel . "</a>\n</li>"; 
    } else { 
     $out.= "<li><a href=\"" . $reload . "&amp;pageno=" . ($page - 1) . "\">" . $prevlabel . "</a>\n</li>"; 
    } 

    $pmin = ($page > $adjacents) ? ($page - $adjacents) : 1; 
    $pmax = ($page < ($tpages - $adjacents)) ? ($page + $adjacents) : $tpages; 
    for ($i = $pmin; $i <= $pmax; $i++) { 
     if ($i == $page) { 
      $out.= "<li class=\"active\"><a href=''>" . $i . "</a></li>\n"; 
     } elseif ($i == 1) { 
      $out.= "<li><a href=\"" . $reload . "\">" . $i . "</a>\n</li>"; 
     } else { 
      $out.= "<li><a href=\"" . $reload . "&amp;pageno=" . $i . "\">" . $i . "</a>\n</li>"; 
     } 
    } 

    if ($page < ($tpages - $adjacents)) { 
     $out.= "<li><a style='font-size:11px' href=\"" . $reload . "&amp;pageno=" . $tpages . "\">" . $tpages . "</a>\n</li>"; 
    } 
    // next 
    if ($page < $tpages) { 
     $out.= "<li><a href=\"" . $reload . "&amp;pageno=" . ($page + 1) . "\">" . $nextlabel . "</a>\n</li>"; 
    } else { 
     $out.= "<span style='font-size:11px'>" . $nextlabel . "</span>\n"; 
    } 
    $out.= ""; 
    return $out; 
} 

$per_page = 3;   // number of results to show per page 
$blgp = $_GET['blgp']; 
$time = $_GET['timing']; 
$pin = $_GET['pin']; 
$result = mysqli_query("SELECT * FROM doner WHERE pincode='".$pin."' AND timing='".$time."' AND blood_gp='".$blgp."'"); 
$total_results = mysqli_num_rows($result); 
$total_pages = ceil($total_results/$per_page);//total pages we going to have 

//-------------if page is setcheck------------------// 
if (isset($_GET['pageno'])) { 
    $show_page = $_GET['pageno'];    //it will telles the current page 
    if ($show_page > 0 && $show_page <= $total_pages) { 
     $start = ($show_page - 1) * $per_page; 
     $end = $start + $per_page; 
    } else { 
     // error - show first set of results 
     $start = 0;    
     $end = $per_page; 
    } 
} else { 
    // if page isn't set, show first set of results 
    $start = 0; 
    $end = $per_page; 
} 
// display pagination 
$page = intval($_GET['pageno']); 

$tpages=$total_pages; 
if ($page <= 0) 
    $page = 1; 
?> 

<div id="main-content" class="main-content"> 
    <div class="container"> 
     <div id="primary" class="content-area"> 
      <div id="content" class="site-content" role="main"> 
       <div class="row"> 

        <div class="first_div" style="text-align:center;"> 
         <div class="div_heading"> 
          <!--<div class="heading_div">S.No.</div>--> 
          <div class="heading_div">PinCode</div> 
          <div class="heading_div">Timing</div> 
          <div class="heading_div">Blood Group</div> 
         </div> 
         <?php 
         $n= 0; 
         // loop through results of database query, displaying them in the table 
         for ($i = $start; $i < $end; $i++) { 
          $n = $n + 1; 
          // make sure that PHP doesn't try to show results that don't exist 
          if ($i == $total_results) { 
           break; 
          } 

          // echo out the contents of each row into a table 

          echo "<div class='content_row'>"; 
           //echo "<div class='content_data'><strong>".$n.".<strong></div>"; 

           echo "<div class='content_data'>".mysqli_result($result, $i, 'pincode')."</div>"; 

           echo "<div class='content_data'>".mysqli_result($result, $i, 'timing')."</div>"; 

           echo "<div class='content_data'>".mysqli_result($result, $i, 'blood_gp')."</div>"; 

          echo "</div>"; 
         } 
         ?> 

        </div> 

        <div class="pagination_section"> 
         <?php 
         $reload = get_page_link() . "?tpages=" . $tpages; 
         echo '<div class="pagination"><ul>'; 
         if ($total_pages > 1) { 
          echo paginate($reload, $show_page, $total_pages); 
         } 
         echo "</ul></div>"; 
         // pagination 
         ?> 
        </div> 
       </div> 
      </div><!-- #content --> 
     </div><!-- #primary --> 
    </div> 
</div>