Welcome Guest, Not a member yet? Register   Sign In
pagination problem
#1

[eluser]gwood[/eluser]
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 ...
#2

[eluser]gwood[/eluser]
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 ????
#3

[eluser]pickupman[/eluser]
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.

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

$KW = $this->session->userdata('KW');
#4

[eluser]InsiteFX[/eluser]
Also please use code tags when posting code.
Helps us view it easier.

Use POST REPLY not FAST REPLY

InsiteFX
#5

[eluser]gwood[/eluser]
@pickupman
Thank you so much. That solved it.

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

[eluser]Unknown[/eluser]
@pickupman
Thank you for your answer
#7

[eluser]Unknown[/eluser]
Thank you! It was very useful to me.
#8

[eluser]Unknown[/eluser]
:coolmad:

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

[eluser]thebigpj[/eluser]
Do session's not destroy themselves after a set period of time?
#10

[eluser]Unknown[/eluser]
Thank you, it was really a good info.




Theme © iAndrew 2016 - Forum software by © MyBB