CodeIgniter使用性别,专业化和城市的Ajax过滤器分页

时间:2015-06-30 08:35:23

标签: ajax codeigniter pagination jquery-pagination codeigniter-pagination

在这里,我将医生的姓名,专业或地点用于搜索,然后按继续进行搜索。

enter image description here

然后我来到这里你可以看到分页的搜索记录。这个分页工作正常,专业化,性别和城市过滤器也可以正常工作,但问题是

enter image description here

当我使用这些过滤器过滤结果时,结果显示完全准确但分页现在根据过滤器工作。这就是我想知道如何解决它。

enter image description here

这是我的搜索医生,专业化或地点 html表单

<form action="site/doctors" method="post" role="form" class="form-home">
<div class="form-group">
<label for="search1">Enter Your Search Criteria:</label>
<input type="text" class="form-control" name="search_doctor" id="search_doctor" placeholder="Enter Doctor's Name, Speciality or Location">
 </div>
<button type="submit" class="btn btn-success pull-right">Continue &raquo;</button>
</form><!-- /Form -->

医生控制器

public function doctors($start=0)
{


        $this->load->model('Doctors_Model');
        //Doctors Specializations
        $data['specializations'] = $this->Doctors_Model->doctors_specializations();
        $data['cities'] = $this->Doctors_Model->cities();

        $data['doctors'] = $this->Doctors_Model->index(2,$start);

        //pagination
        $query = $this->input->post('search_doctor');
        $sql = "SELECT doctors.id,doctors.doctor,doctors.gender,doctors.username,doctors.contactno,doctors.email,doctors.city,doctors.address,
        doctors.country,doctors.profile,
        specialist.specialist
        from doctors_specialists_bridge
        LEFT JOIN doctori4_PakDoctors.doctors 
        ON (doctors.id = doctors_specialists_bridge.doctorid)
        LEFT JOIN doctori4_PakDoctors.specialist 
        ON (specialist.id = doctors_specialists_bridge.specialistid)
        WHERE doctors.doctor LIKE '%$query%' OR specialist.specialist LIKE '%$query%'
        ";          
        $q = $this->db->query($sql);
        //echo $q->num_rows();
        //exit;

        $this->load->library('pagination');
        $config['base_url']=base_url("/site/doctors/");
        $config['total_rows']=$q->num_rows();
        $config['per_page']=2;
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_link'] = '&lt;';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&gt;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="current"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['first_link'] = '&lt;&lt;';
        $config['last_link'] = '&gt;&gt;';
        $this->pagination->initialize($config);
        $data['pages']=$this->pagination->create_links();

        $data['site_title'] = 'Doctors';
        $data['main_content']='doctors';
        $this->load->view('includes/template',$data);


}//end doctors

过滤控制器

public function doctors_filter(){



    //echo $this->uri->segment(3);
    $this->load->model('Doctors_Model');
    $search_query = $this->Doctors_Model->doctors_filtered();


    if($search_query){
        $html = '';

    foreach($search_query as $doctor){

        $html.='<div class="result"><div class="row">
                        <div class="col-md-2 col-sm-3 col-xs-3">
                        <a href="'. base_url('site/doctor/'.$doctor->username) .'">
                            <img alt="doctor\'s profile" src="'.base_url('doctordirectory-theme/images/doctors/maria.jpg').'" class="img-circle" />
                        </a>
                        </div>
                        <div class="col-md-6 col-sm-9 col-xs-9">
                            <ul class="list-unstyled doctors-info">
                                <li> <i class="fa fa-user-md"></i> '. ucwords($doctor->doctor).' | '.ucwords($doctor->specialist).' </li>
                                <li> <i class="fa fa-female"></i> '. ucwords($doctor->gender).' </li>
                                <li> <i class="fa fa-envelope"></i> '. $doctor->email .' </li>
                                <li> <i class="fa fa-map-marker"></i> '. ucwords($doctor->city).' </li>
                                <li> <i class="fa fa-home"></i> '. ucwords($doctor->address).' </li>
                            </ul>
                        </div>
                        <div class="col-md-4 col-sm-12 col-xs-12">
                            <ul class="list-unstyled heart-bg-area">
                                <li> <i class="fa fa-heart fa-4x"></i> </li>
                                <li> ( 10 ) </li>
                                <li> Click on the heart above to like this Doctor. </li>
                            </ul>
                        </div>
                    </div></div>';



    }
    echo $html;
    }else{ ?>

       <div class="result"> <div class="row">


            <div class="col-md-12">
            <p>No Records Found!</p>
            </div>


        </div><!-- /row--></div>
    <?php }


    }   

医生型号

public function index($num=2,$start=0)
{
 $query = $this->input->post('search_doctor');
 $sql = "SELECT doctors.id,doctors.doctor,doctors.gender,doctors.username,doctors.contactno,doctors.email,doctors.city,doctors.address,
        doctors.country,doctors.profile,
        specialist.specialist
        from doctors_specialists_bridge
        LEFT JOIN doctori4_PakDoctors.doctors 
        ON (doctors.id = doctors_specialists_bridge.doctorid)
        LEFT JOIN doctori4_PakDoctors.specialist 
        ON (specialist.id = doctors_specialists_bridge.specialistid)
        WHERE doctors.doctor LIKE '%$query%' OR specialist.specialist LIKE '%$query%'
        LIMIT $start,$num";         
        $q = $this->db->query($sql);
        return $q->result();

}

过滤模型

public function doctors_filtered(){


        $gender = $_REQUEST['gender'];
        $city = $_REQUEST['city'];
        $check = isset($_REQUEST['check']);

             $sql = "SELECT doctors.id,doctors.doctor,doctors.gender,doctors.username,doctors.contactno,doctors.email,doctors.city,doctors.address,
                    doctors.country,doctors.profile,
                    specialist.specialist
                    FROM doctors_specialists_bridge
                    INNER JOIN doctori4_PakDoctors.doctors 
                    ON (doctors.id = doctors_specialists_bridge.doctorid)
                    INNER JOIN doctori4_PakDoctors.specialist 
                    ON (specialist.id = doctors_specialists_bridge.specialistid)";




                        $ddd=0;
                        if($gender!="Any" || $city!="Any" || $check!='')
                        {
                            $sql.="WHERE ";
                        }

                        if($check!=''){
                            $sql.=" ( ";
                            foreach ($_REQUEST['check'] as $value)
                                {



                                    if($ddd==1)
                                    {
                                        $sql.=" OR ";
                                    }
                                    $ddd=1;
                                    $sql.="specialist='".$value."' ";

                                }
                                $sql.=" ) ";


                        }


                        if($gender!="Any"){
                            if($ddd==1)
                            {
                                $sql.=" AND ";
                            }
                        $sql.="gender='".$gender."'";
                        $ddd=1;
                        }



                        if($city!="Any"){ 
                            if($ddd==1)
                            {
                                $sql.=" AND ";
                            }
                            $sql.="city='".$city."'"; 
                            $ddd=1;
                        } 



        $q = $this->db->query($sql);
        if($q->num_rows()>0){
                foreach($q->result() as $row){
                    $data[] = $row;
                    }//end foreach
            return $data;
            }//endif



    }

这是JQUERY / AJAX代码

<script type="text/javascript">

    $(document).ready(function () {

        $( "input[type=checkbox]" ).on( 'click', function(){




            //console.log($(this).serialize());

            //var values = $('#form1').serialize();
            var values = $('form').serialize();

            var controller = 'site';
            var base_url = '<?php echo site_url(); ?>';
            var  myurl = base_url + controller + '/doctors_filter/';


            $.ajax({
                type: "POST",
                url: myurl,
                data: values,
                complete: function (data) {
                    //alert(data.responseText);
                    $('#result').empty().html(data.responseText)
                    //console.log(data.responseText);
                }
            });


        } );


        $('#gender,#city').on('change', function () {
            //var values = $('#form1').serialize();
            var values = $('form').serialize();

            var controller = 'site';
            var base_url = '<?php echo site_url(); ?>';
            var  myurl = base_url + controller + '/doctors_filter/';

            //console.log(myurl);

            $.ajax({
                type: "POST",
                url: myurl,
                data: values,
                complete: function (data) {
                   //alert(data.responseText);
                    $('#result').empty().html(data.responseText)
                }
            });
        })
    });
</script>

由于

0 个答案:

没有答案