在Codeigniter中过滤数据时分页不起作用

时间:2019-03-15 08:51:29

标签: php jquery codeigniter

search-job.php

<input type="checkbox" name="category" id="It jobs" class="category"> It jobs
<input type="checkbox" name="category" id="Hr jobs" class="category"> Hr jobs
<input type="checkbox" name="category" id="Hardware jobs" class="category"> Hardware jobs
<script>
    $(document).ready(function(){
        $(".category").click(function(){
            key = this.id;
            $.ajax({
               type:"POST",
               data:{"key":key},
               url:"<?php echo base_url(); ?>key_job",
               success:function(data){
                   $("#search_filter_job").html(data);
               }
            });
        });
    });
<script>

控制器:

public function search_key_job()
{
    $category = $this->input->post('key');

    $config = array();
    $config["base_url"] = base_url()."welcome/search-job";
    $config["total_rows"] = $this->user_data->search_filter_count($category);
    $config["per_page"] = 7;
    $config["uri_segment"] = 3;
    $this->pagination->initialize($config);
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data['result'] = $this->user_data->search_filter($category,$config["per_page"], $page);
    $data["links"] = $this->pagination->create_links();

    $this->load->view('search_key_job',$data);
}

型号:

public function search_filter($category,$limit, $start)
{
    $where = "category='".$category."'";
    $this->db->where($where);
    $this->db->limit($limit, $start);
    $query = $this->db->get("job");
    if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            $data[] = $row;
        }
        return $data;
    }
    else
    {
        $this->session->set_flashdata('error_msg','<p>We are sorry. No job found</p>');
    }
    return false;
}

public function search_filter_count($category)
{
    $this->db->select('*');
    $this->db->from('job');
    $where = "category='".$category."'";
    $this->db->where($where);
    $query = $this->db->get();
    $result = $query->num_rows();
    return $result;
}

search_key_job.php

<?php
    foreach($result as $row)
    {
?>  
        <h5><?php echo $row->job_title; ?></h4> 
<?php
    }
?>
<p style="text-align: center;width: 73.5%;"><?php echo $links; ?></p>

在此代码中,我有多个checkbox with name="category"现在,当我单击某个特定类别时,我在这里做什么,然后工作正在显示并且分页也可以正常工作,但是单击下一个分页按钮会刷新页面并显示给我search-job.php页,但我只想显示复选框过滤器分页数据。那么,我该怎么做?请帮助我。

谢谢

1 个答案:

答案 0 :(得分:0)

您应该在复选框名称中添加<template> <div> <div v-if="this.$metaInfo.htmlAttrs.lang === 'de-DE'">{{homepage.germanTitle}}</div> <div v-else>{{homepage.englishTitle}}</div> </div> </template> <script> import gql from 'graphql-tag' export default { apollo: { homepage: gql` { homepage { id title englishTitle: title(locale: en) germanTitle: title(locale: de) } } ` } } </script>

示例:

[]