2016-05-18 2 views
0

Ich habe einen Code für die Suche und Paginierung in ihm erstellt. Wenn ein Benutzer in einer Branche suchen möchte, werden Daten dagegen angezeigt. Aber wenn er irgendeine Option in der Seitennummerierung drückt, dann zeigt es alle Daten an, die mit jeder Industrie in Verbindung stehen. Wie kann ich die Paginierung im Zusammenhang mit dem Suchergebnis anzeigen? Und wenn der Benutzer eine Branche ausgewählt hat, sollte diese ausgewählt werden, wenn der Benutzer auf Seite 2 oder Seite 3 oder andere wechselt.Paginierung funktioniert nicht richtig in der Suche

Code of page

  <?php 
     $pd=(isset($script['details']) ? $script['details']:array()) ; 
     //jobs search and normal page view 
     $qstr=Querystring(); 
     $obj_pagination = new Pagination(); 
     $obj_pagination->limit = (($FP_LIMIT!="") ? $FP_LIMIT:10); 
     $pagid=1; 
     if(isset($qstr["page"])) { 
      $pagid=$qstr["page"]; 
     } 
     $obj_pagination->page = $pagid; 
     $srcqry=""; 
     $industry=0; 
     if(isset($_POST['industry'])){ 
      if(isset($_POST['industry'])){ 
       if($_POST['industry']!="0") { 
        $srcqry=$srcqry." AND j.industry ='".(int)$_POST['industry']."'"; 
        $industry=(int)$_POST['industry']; 
       } 
      } 
      $nrs = $obj->query("SELECT * FROM jobs j WHERE j.status='1' ".$srcqry); 
     } else { 
      $nrs = $obj->query("SELECT * FROM jobs j WHERE j.status='1' ".$srcqry); 
     } 
     $tot_rec= count($nrs->rows); 
     $obj_pagination->total = $tot_rec; 
     $obj_pagination->url = "jobs?page={page}"; 
     $num_pages = ceil($obj_pagination->total/$obj_pagination->limit); 
     $start = ($obj_pagination->page-1)*$obj_pagination->limit; 
     $end = $obj_pagination->limit; 
     $limit = "LIMIT $start,$end"; 
     $check; 
     ?> 
     <h3>Search</h3> 
       <form name="srchjobs" action="/jobs" method="post"> 
       <div class="col1"> 
        <select class="dropdown1 spacer_side" name="industry"> 
         <option value="0">All Industries</option> 
         <?php $indrow=getAllIndustries(); 
         if(count($indrow) > 0) { 
          foreach($indrow as $tr) {?> 
           <option value="<?php echo $tr['id']; ?>" <?php if($tr['id']==$industry) { ?> selected="selected"<?php } ?>><?php echo $tr['name']; ?></option> 
           <?php } 
           $check=$tr['name']; 
           } 
           ?> 
        </select> 
       </div> 
       <button type='submit'>Search</button> 
       </form> 
     <?php 
      $indrow=getAllIndustries(); 
      $sql="SELECT j.*,u.url FROM jobs as j, aliases as u WHERE j.status='1' ".$srcqry." 
      AND (j.id=u.slog_id AND u.slog='jobs') ORDER BY j.id DESC ".$limit; 
      $jresults = $obj->query($sql); 
      if($jresults->rows) { 
       foreach($jresults->rows as $j){ 
        $empd=array(); 
        $empd=getIndinfo($j['industry']); 
        $emplogo="/uploads/no-image.png"; 
        ?> 
        <a href="javascript:;"><img src="<?php echo $emplogo;?>" alt="dell1" height="66" width="66" /></a> 
        <a href="<?php echo $j['url']; ?>"><h5><?php echo $j['title']; ?></h5></a> 
        <a href="/job-apply?id=<?php echo $j['id'];?>" class="appler" value="">APPLY</a> 
        <?php } ?> 
        <ul class="pagination"> 
         <?php 
          $obj_pagination->text_next = "&#62;"; 
          $obj_pagination->text_prev = "&#60;"; 
          $obj_pagination->text_first = "&#171;"; 
          $obj_pagination->text_last = "&#187;"; 
          $obj_pagination->text = "Showing {start} to {end} of {total}"; 
          echo $obj_pagination->render(); 
        ?></ul> 
        <?php } else { ?> 
           <span class="latest_job">No jobs Found</span> 
      <?php } ?> 

Abfragezeichenfolgeflag Funktionscode

function Querystring(){ 
    $_G=array(); 
    $REQUEST_URI = $_SERVER['REQUEST_URI']; 
    $REQUEST_URI_ARR = explode("?",$REQUEST_URI); 
    $REQUEST_URI_ARR_All = explode("&",$REQUEST_URI_ARR[1]); 
    foreach($REQUEST_URI_ARR_All as $key=>$val){ 
      $gs = explode("=",$val); 
      if(isset($gs[0]) && isset($gs[1])) 
          $_G[$gs[0]] = urldecode($gs[1]); 
    } 
    return $_G; 
} 

Antwort

-1

Output Ihre Ergebnisse in einer Tabelle und nur eine jquery aktiviert Tabellenklasse verwenden. Auf diese Weise erfolgt die Paginierung automatisch. Stellen Sie sicher, dass Sie auch ein Tag haben.

+0

irgendeine Idee über die Methode oben –

+0

Tun Sie es einfach in Ihrer foreach Schleife. 'foreach ($ Ergebnisse als $ r) { echo $ r ['id']; } ' –

+0

welche für jede Schleife –