Pagination in search result

#1
[eluser]_TTT_[/eluser]
Hi.
I have view where is a search form. Also contoller and model.
I do pagination for all my records

controller site
Code:
function records () {
            // Paginator settings
            $paginator_config['base_url'] = base_url().'site/records/';
            $paginator_config['total_rows'] = $this->db->get('recods')->num_rows();
            $paginator_config['per_page'] = 3;
            $paginator_config['num_links'] = 3;

            $this->pagination->initialize($paginator_config);

  
   $data['records'] = $this->records_model->get_records($this->uri->segment(3),2);

}

its work, but how to do pagination for this:

Code:
function search() {
    $keywords = $_POST['keywords'];

    // get search result
    $data['result'] = $this->records_model->search_records($keywords);
}

#2
[eluser]_TTT_[/eluser]
and one more question about pagination.
with out CI I may use this index.php?order=name&page=2 its work.
how to do it in CI ?

#3
[eluser]natefons[/eluser]
in your total rows, use the where clause to filter down the search.
Code:
$paginator_config['total_rows']=$this->db->get_where('records', array('search' => $SEARCH_TERMS));


now for the records, same way, u would use the search term.

"Select * from `records` WHERE `search`='SEARCHTERM' LIMIT '".$limit."','".$offset."';";


at least this is how i did it. (i used sql queries, rather than active records)


not sure if this is the simplest.

#4
[eluser]natefons[/eluser]
for your 2nd question,
add a config:
$config['page_query_string'] = TRUE

#5
[eluser]_TTT_[/eluser]
I cant understend what this mean

$this->db->get_where('records', array('search' => $SEARCH_TERMS));

what is "search" in this query ?

and its

“Select * from `records` WHERE `search`=‘SEARCHTERM’ LIMIT ‘“.$limit.”’,’”.$offset.”’;”;

I dont think it is in function
function get_where() {
......
“Select * from `records` WHERE `search`=‘SEARCHTERM’ LIMIT ‘“.$limit.”’,’”.$offset.”’;”;
.....
}


Please be more detail

#6
[eluser]_TTT_[/eluser]
[quote author="natefons" date="1285188493"]for your 2nd question,
add a config:
$config['page_query_string'] = TRUE[/quote]

this config for pagination ?

I have link like this now

site/records/first_name&per_page=2

but its error


An Error Was Encountered
The URI you submitted has disallowed characters

#7
[eluser]_TTT_[/eluser]
I found it in config.php.

Now I have urls
/entries/order/first_name&per_page=2

but it is A Database Error Occurred

this part
...ORDER BY first_name&per_page=2 DESC LIMIT 0,2...

#8
[eluser]natefons[/eluser]
no its both.

first its in the config.php file

next you need to init. the pagination.

in your case
$pagination_config['page_query_string']=true;

#9
[eluser]_TTT_[/eluser]
function order ($order) {
// Paginator settings
$paginator_config['base_url'] = base_url().'site/order/';
$paginator_config['total_rows'] = $this->db->get('recods')->num_rows();
$paginator_config['per_page'] = 3;
$paginator_config['num_links'] = 3;
$paginator_config['page_query_string'] = TRUE;
$page_per = 2;

$this->pagination->initialize($paginator_config);


$uriseg = $this->uri->segment(4);
if(empty($uriseg)) { $uriseg = 0; }

$data['records'] = $this->records_model->get_records($uriseg,$page_per,$order);
....

}


and in config.php

$config['enable_query_strings'] = TRUE;


And I have url site/order/first_name&per_page=1

Database error

......ORDER BY first_name&per_page=1 DESC LIMIT first_name&per_page=1,2......

#10
[eluser]natefons[/eluser]
here is how i did mine...

Code:
$search_term=$this->input->post('search'); //make sure to escape it!!
$query="Select * from `trades` WHERE `title` LIKE '%".$search_term."%';";
$result=$this->db->query($query);
$config['base_url']= 'http://localhost/index.php/search/index';
        $config['per_page']=10;
        $config['num_links']=20;
        $config['full_tag_open']='<div id="pag">';
        $config['full_tag_close']='</div>';
        $config['first_link'] = 'First';
        $config['first_tag_open'] = '<div>';
        $config['first_tag_close'] = '</div>';
        $config['last_link'] = 'Last';
        $to=$this->uri->segment(3);
        if(empty ($to))
            $to=0;
        $result=$this->db->query($query);
        $config['total_rows']= $result->num_rows();
        $this->pagination->initialize($config);

and for getting the records:
Code:
$query="Select * from `trades` WHERE `title` LIKE '%".$search_term."%' OR `message` LIKE '%".$search_term."%' ORDER BY `title`;";
         $result=$this->db->query($query);

if ($result->num_rows() > 0)
        {
            foreach ($result->result() as $row)
            {
              //print result details $row->title, $row->message etc etc
            }
       }


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.