Your Location is: Home > Cakephp

CakePHP Ajax search : Showing same data two times for pagination

From: China View: 3209 Alimon Karim 


Here ajax search working fine but the problem is same data is showing two times, because I have given pagination limit 2.If I make it 3, same result is showing 3 times.

Here is my index.ctp

$( "#search" ).keyup(function() {

    var value=$('#search').val();   

        $.get("<?php echo   Router::url(array('controller'=>'userTypes','action'=>'search'));?>",{search:value},function(data){

Here is my search action

public function search()
        $request=$this->UserType->find('all', array(
        'conditions' => array(' LIKE' => "%$search%")

Here is the search.ctp

<?php foreach($usertype as $usertypes) { ?>
            <td><?php echo $usertypes['UserType']['id']; ?></td>
            <td><?php echo $usertypes['UserType']['name']; ?></td>
            <td><?php echo $usertypes['UserType']['description']; ?></td>

<?php } ?>

Pagination limit In appcontroller

            $this->Paginator->settings = array(

Result is showing me like this

enter image description here

May anybody help me for solve it ?

Best answer

If you want to use pagination, your search method should look like this:

public function search()
       $search = $this->request->query['search'];
       $search = '';
    $this->Paginator->settings = array(
        'conditions' => array(' LIKE' => "%$search%"),
        'limit' => 2