EllisLab text mark
Advanced Search
     
pagination problem
Posted: 10 April 2010 09:28 AM
Joined: 2010-04-10
7 posts

Okay, I am pretty new in CI and I am stuck on pagination. I am performing this pagination on a record set that is result of a query. Now everything seems to be working fine. But there’s some problem probably with the link. I am displaying 10 results per page. Now if the results are less than 10 then it’s fine. Or If I pull up the entire records in the table it works fine. But in case the result is more than 10 rows, then the first 10 is perfectly displayed, and when I click on the pagination link to get to the next page the next page displays the rest of the results from the query as well as, other records in the table. ??? I am confused.. Any help??

Here’s the model code I am using ....

function getTeesLike($field,$param)
{
$this->db->like($field,$param);
$this->db->limit(10, $this->uri->segment(3));
$query=$this->db->get('shirt');
if($query->num_rows()>0){
return $query->result_array();
}
}

function getNumTeesfromQ($field,$param)
{
$this->db->like($field,$param);
$query=$this->db->get('shirt');
return $query->num_rows();
}

And here’s the controller code ....

$KW=$this->input->post(‘searchstr’);
$this->load->library(‘pagination’);
$config[‘base_url’]=‘http://localhost/cit/index.php/tees/show/’;
$config[‘total_rows’]=$this->T->getNumTeesfromQ(‘Title’,$KW);
$config[‘per_page’]=‘10’;
$this->pagination->initialize($config);
$data[‘tees’]=$this->T->getTeesLike(‘Title’,$KW);
$data[‘title’]=‘Displaying Tees data’;
$data[‘header’]=‘Tees List’;
$data[‘links’]=$this->pagination->create_links();
$this->load->view(‘tee_res’, $data);

//What am I doing wrong here ???? Pls help ...

 
Posted: 10 April 2010 01:34 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2010-04-10
7 posts

played around a little more with the code and I guess nothing is wrong with the pagination code, however things are getting messed up because of this $KW=$this->input->post(‘searchstr’); , well thats what i think, cuz when I comment that line out and hard code a value for $KW, it just works fine… any idea why? any other way to pass the value of input without post ????

 
Posted: 10 April 2010 01:57 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2009-03-30
1317 posts

You are losing $KW = $this->input->post(‘searchstr’); on the next page. Post is only available on the page immediately after it’s submitted. Store the keyword in a session. That way when you click on page two, the post is longer available and the keyword will be pulled from the user’s session instead. Make sure you have loaded the session library.

$KW $this->input->post('searchstr');
if(
strlen($KW) > 0){
   $this
->session->set_userdata('KW',$KW);
}

$KW 
$this->session->userdata('KW'); 
 
Posted: 10 April 2010 02:12 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6707 posts

Also please use code tags when posting code.
Helps us view it easier.

Use POST REPLY not FAST REPLY

InsiteFX

 Signature 

Certified State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

Skype: insitfx

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 10 April 2010 02:30 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2010-04-10
7 posts

@pickupman
Thank you so much. That solved it.

@InsiteFX
Sure.Okay.
First time here.. me acting like n00b ...never mind

 
Posted: 01 October 2010 10:25 AM   [ # 5 ]   [ Rating: 0 ]
Joined: 2010-07-04
2 posts

@pickupman
Thank you for your answer

 
Posted: 21 December 2010 06:25 AM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-21
1 posts

Thank you! It was very useful to me.

 
Posted: 20 March 2013 08:48 AM   [ # 7 ]   [ Rating: 0 ]
Joined: 2013-03-20
2 posts

cool mad

useful but you will need to destroy the session at some point in time

 
Posted: 20 March 2013 10:53 AM   [ # 8 ]   [ Rating: 0 ]
Joined: 2012-08-15
16 posts

Do session’s not destroy themselves after a set period of time?

 
Posted: 26 March 2013 01:36 AM   [ # 9 ]   [ Rating: 0 ]
Joined: 2013-03-26
1 posts

Thank you, it was really a good info.