分页在搜索中不能正常工作

时间:2016-05-18 07:06:50

标签: php search pagination

我已经在其中创建了一些搜索和分页代码。如果用户想要使用某个行业进行搜索,则会显示数据。但无论何时他在分页中按任何选项,它都会显示与每个行业相关的所有数据。如何显示与搜索结果相关的分页。如果用户选择了任何行业,那么如果用户移至第2页或第3页或任何行业,则应选择该行业。

页面代码

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

查询字符串功能代码

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

1 个答案:

答案 0 :(得分:-1)

在表中输出结果,只使用启用了jquery的表类。这样分页将是自动的。确保你也有一个标签。