分页查询无效

时间:2015-08-28 06:13:31

标签: php codeigniter pagination

我的分页存在问题。我的方案是我只是过滤器然后点击搜索。然后结果将显示输出。但是,当我点击第2页时,它会返回查询,而不是被过滤的查询。

  

控制器

<?php //CONTROLLER
function maintenance(){

        if($this->session->userdata('l@ginUs3r')) {

            $session_data = $this -> session -> userdata('l@ginUs3r');
            $data['u_id'] = $session_data['u_id'];
            $data['u_uname'] = $session_data['u_uname'];
            $data['u_pword'] = $session_data['u_pword'];
            $data['u_role'] = $session_data['u_role'];
            $data['is_active'] = $session_data['is_active']; 

            $config = array();
            $config["base_url"] = base_url() . "personnel/maintenance/";
            $config["total_rows"] = $this -> Main -> count_prf();
            $config["per_page"] = 10;
            $config["uri_segment"] = 3;
            $this->pagination->initialize($config);
            $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
            $data['prf'] = $this -> Main -> select_prf($config['per_page'], $page);
            $data["prf_links"] = $this->pagination->create_links();

                if(isset($_POST['search']))
                    {
                            if($_POST['division'] != "" && $_POST['group'] != "" && $_POST['department'] != "" && $_POST['position'] != "" )
                            {
                                if($_POST['date_rec'] != "" && $_POST['date_upto'] != "")
                                {
                                    $where = "prf_div = '".$_POST['division']."' AND prf_group = '".$_POST['group']."' AND prf_status = '".$_POST['prf_status']."' AND prf_dept = '".$_POST['department']."' AND prf_position = '".$_POST['position']."' AND prf_status = '".$_POST['prf_status']."' AND prf_daterec BETWEEN '".$_POST['date_rec']."' AND '".$_POST['date_upto']."' ";
                                }

                                else
                                {
                                    $where = "prf_div = '".$_POST['division']."' AND prf_group = '".$_POST['group']."' AND prf_status = '".$_POST['prf_status']."' AND prf_dept = '".$_POST['department']."' AND prf_position = '".$_POST['position']."' AND prf_status = '".$_POST['prf_status']."' ";
                                }

                            }
                            //NEXT IF FOR SEARCH
                            if($_POST['division'] == "" && $_POST['group'] == "" && $_POST['department'] == "" && $_POST['position'] == "" )
                            {
                                if($_POST['date_rec'] != "" && $_POST['date_upto'] != "")
                                {
                                    $where = "prf_status = '".$_POST['prf_status']."' AND prf_daterec BETWEEN '".$_POST['date_rec']."' AND '".$_POST['date_upto']."' ";
                                }

                                else
                                {
                                    $where = "prf_status = '".$_POST['prf_status']."' ";

                                }

                            }
                                    $_SESSION['page_list'] = $where;

                                    $config = array();
                                    $config["base_url"] = base_url() . "personnel/maintenance/";
                                    $config["total_rows"] = $this -> Main -> count_prf_where($_SESSION['page_list']);
                                    $config["per_page"] = 10;
                                    $config["uri_segment"] = 3;
                                    $this->pagination->initialize($config);
                                    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
                                    $data["prf"] = $this -> Main -> fetch_prf($_SESSION['page_list'], $config["per_page"], $page);
                                    $data["prf_links"] = $this->pagination->create_links();
                    }
            $this -> load -> view('templates/header', $data);
            $this -> load -> view('pages/maintenance', $data);


$this -> load -> view('templates/footer');

            } else {

                $this -> load -> view('templates/lheader');
                $this -> load -> view('pages/login');
                $this -> load -> view('templates/footer');

            }

        }
  ?> 
  

查看

<button type="button" class="btn btn-success btn-search-cust1 pull-right" onclick="window.location.href='<?=base_url()?>personnel/add_prf'"><span class="icon-file"></span></button>

<button type="button" name="back" class="btn btn-success btn-search-cust pull-right" onclick="window.location.href='<?=base_url()?>personnel/home'"> <span class="icon-home"></span> </button>

<?php $this -> load -> view('templates/maintenance-navbar'); ?>

<article class="grid_12 panel">

    <div class=""><span class=""> </span><label class="listnames">Filter</label></div>

    <div class="tab-field">

    <form method="POST" action="<?=base_url()?>personnel/maintenance">

        <label class="listnames">Division</label>

        <select class="cust_fields" name="division">

            <option value="">--Select--</option>

            <?php if(!$ddl2){ ?>

                <option value=""><?="NO DATA"?></option>

            <?php } else { ?>

                <?php foreach($ddl2 as $row){ ?>

                <option value="<?=$row['d_id']?>"><?=$row['d_divname']?></option>

                <?php } ?>

            <?php } ?>

        </select>


        <label class="listnames">Group</label>

        <select class="cust_fields" name="group">

            <option value="">--Select--</option>

            <?php if(!$ddl2){ ?>

                <option value=""><?="NO DATA"?></option>

            <?php } else { ?>

                <?php foreach($ddl1 as $row){ ?>

                <option value="<?=$row['g_id']?>"><?=$row['g_name']?></option>

                <?php } ?>

            <?php } ?>

        </select>

        <label class="listnames">PRF Status<!--FORMERLY ROLE --></label>

        <select name="prf_status" id="roles" class="cust_fields">

            <option value="Outstanding">Outstanding</option>
            <option value ="Served">Served</option>

        </select>

        <br>

        <label class="listnames">Department</label>

        <select name="department" id="roles" class="cust_fields">

            <option value="">--Select--</option>

            <?php if(!$ddl3){ ?>

                <option value=""><?="NO DATA"?></option>

            <?php } else { ?>

                <?php foreach($ddl3 as $row){ ?>

                <option value="<?=$row['dept_id']?>"><?=$row['dept_name']?></option>

                <?php } ?>

            <?php } ?>

        </select>

        <label class="listnames">Position</label>

        <select name="position" id="roles" class="cust_fields">

            <option value="">--Select--</option>

            <?php if(!$ddl5){ ?>

                <option value=""><?="NO DATA"?></option>

            <?php } else { ?>

                <?php foreach($ddl5 as $row){ ?>

                <option value="<?=$row['r_id']?>"><?=$row['r_rank']?></option>

                <?php } ?>

            <?php } ?>

        </select>

        <label class="listnames">Date Received</label>

        <input type="date" name="date_rec" placeholder="mm/dd/yyyy" id="fromdate" autocomplete="off"  style="height: 24px; width: 128px;">

        <label class="listnames" style = "width: 15px;">To</label>

        <input type="date" name="date_upto" placeholder="mm/dd/yyyy" id="fromdate" autocomplete="off"  style="height: 24px; width: 128px;">

        <button type="submit" name="search" class="btn btn-success cust_search"><span class="icon-search2"></span></button>

        <!-- <input type="submit" name="search" value="Search"> -->

    </form>




    </div>

</article>


<table class="table">

        <tr class="thead1" style = "background: #D6C9A4;">


            <div class="row">
            <div class="col-md-3">
              <div class="row"><div class="col-md-3"><th >Division</th></div><div class="col-md-3"><th >Group</th></div><div class="col-md-3"><th >Department</th></div></div>
          </div>
            <div class="col-md-3">
              <div class="row"><div class="col-md-3"><th >Position</th></div><div class="col-md-3"><th >Rank</th></div><div class="col-md-3"><th >Ex. No. of Personnel</th></div></div>
          </div>
            <div class="col-md-3">
              <div class="row"><div class="col-md-3"><th >No. of Req. Personnel</th></div><div class="col-md-3"><th >No. of Served Personnel</th></div><div class="col-md-3"><th >Reason for PRF</th></div></div>
          </div>
            <div class="col-md-3">
              <div class="row"><div class="col-md-3"><th >Date Received</th></div><div class="col-md-3"><th >Date Served</th></div><div class="col-md-3"><th >Age of PRF</th></div><div class="col-md-3"><th >PRF Status</th></div></div>
          </div>
        </div>

        </tr>
        <?php 

        if(!$prf)
        {

        ?>
            <h3 class="tab-field">No Data</h3>
        <?php

        }
        $x = 1;
        foreach($prf as $row){ 
            $id = $row['prf_id'];
            $now = time();
            $your_date = strtotime($row['prf_daterec']);
            $datediff = $now - $your_date;
            $age = floor($datediff/(60*60*24));
            $date_rec = substr($row['prf_daterec'], 0, -13);
            $date_serv = substr($row['prf_dateserv'], 0, -13);

        ?>
        <tr id="active" onclick="window.location.href='<?=base_url()?>personnel/prf_info/<?=$id?>'">

            <td><?=strtoupper($row['d_divname'])?></td>
            <td><?=strtoupper($row['g_name'])?></td>
            <td><?=strtoupper($row['dept_name'])?></td>
            <td><?=strtoupper($row['prf_position'])?></td>
            <td><?=strtoupper($row['r_rank'])?></td>
            <td><?=strtoupper($row['prf_ex_no_personnel'])?></td>
            <td><?=strtoupper($row['prf_no_req_personnel'])?></td>
            <td>Served Personnel</td>
            <td><?=strtoupper($row['prf_reason'])?></td>
            <td><?=$date_rec?></td>
            <td><?=$date_serv?></td>
            <td><?=$age?> Days</td>
            <td><?=$row['prf_status']?></td>

        </tr>               

        <?php } ?>

    </table>

    <div class="pagination-align"><?=$prf_links?></div>

0 个答案:

没有答案