Welcome Guest, Not a member yet? Register   Sign In
Please help with Pagination - SOLVED
#1

[eluser]laytone[/eluser]
I'm trying ti implement pagination for my first time. Its working, but the numbers at the bottom of don't update to the current page. i.e. if you click '3' the third page shows up but the pagination navigation still shows page one. What am I doing wrong? Please help!

If I click on page three this is the uri I come up with and results 41 - 60 show up:
/salesmanager/searchsales/search/40

But pagination still says 1 2 3 > Last ›

sorry my controller is a little messy but you know how it is the first time you try to do something!

Controller Function:
Code:
public function search($start = '0', $page = '1'){
        if($this->input->post('searchsubmit')){
            $searchdata = array(
                'bdate' => date('Y-m-d', strtotime($this->input->post('bdate'))). ' 00:00:00',
                'edate' => date('Y-m-d', strtotime($this->input->post('edate'))). ' 23:59:59',
                'search_by' => $this->input->post('search_by'),
                'search_for' => $this->input->post('search_for'),
                'show_all' => $this->input->post('show_all'),
                'traffic_source' => $this->input->post('traffic_source'),
            );
            $cs = $searchdata;
            $this->session->set_userdata('cs', $cs);
        }
        $this->searchdata = $this->session->userdata('cs');
        if (!$this->searchdata){
            redirect ($this->myPreuri . '/index');
            return;
        }
        $this->searchdata['start'] = $start;
        $this->searchdata['limit'] = '20';
        $this->session->set_userdata('cs', $this->searchdata);
        
        $this->Mymodel->searchdata = $this->searchdata;
        $count = $this->Mymodel->get_count();
        $result = $this->Mymodel->dosearch();
        
        if(!$result){
            echo "No Results for this search use the back button and try again!";
            return;
        }    
        
        $pagedata['sr'] = $result;
        $pagedata['count'] = $count;
        $pagedata['start'] = $start;
        $pagedata['limit'] = '20';
        
        $this->load->library('pagination');
        
        $config['base_url'] = base_url().'/'.$this->myPreuri.'/search/';
        $config['total_rows'] = $count;
        $config['per_page'] = '20';
        $config['uri_segment'] = 5;
        $config['cur_page'] = $count / $start;
        $this->pagination->initialize($config);
        
        $this->_showPage('searchresults', $pagedata, "Search Results" );
        
    }

My Model:
Code:
class Managesalesmodel extends Model {
    
    var $searchdata = '';
    
    public function __construct(){
        parent::Model();
    }
    
    function setupquery(){
        $search = (object)$this->searchdata;
        $this->db->select('id,first_name, last_name, active, email, phone, zip');
        //first set the date range
        $this->db->where('register_date >=', $search->bdate);
        $this->db->where('register_date <=', $search->edate);
        //then what set the by what for what
        $this->db->like($search->search_by, $search->search_for);
        //then we filter the ocmpany
        if ($search->traffic_source != 'all')
            $this->db->where('traffic_source', $search->traffic_source);
        //Set the limit
        $this->db->from('people');    
    }
    
    public function get_count(){
        $this->setupquery();
        return $this->db->count_all_results();
    }
    
    public function dosearch(){
        $this->setupquery();
        $search = (object)$this->searchdata;
        $this->db->limit($search->limit, $search->start);
        //Get the result
        $query = $this->db->get();
        //Return the result!
        return $query->num_rows() >= 1 ? $query->result() : FALSE;
    }
}

My View:

Code:
<table border="0" align="center" cellpadding="3" cellspacing="1" style="border: 1px solid black;">
  <tr>
      <th scope="col">#</th>
    <th scope="col" nowrap="nowrap">Name</th>
    <th scope="col">Email</th>
    <th scope="col">Phone</th>
    <th scope="col">Zip</th>
  </tr>
  &lt;?php
      $rnum = $start;
    foreach($sr as $r):
        ++$rnum;
        $bgcolor = 'cccccc';
        if (($rnum % 2) == 0) $bgcolor = 'dddddd';
    ?&gt;
  <tr bgcolor="#&lt;?php echo $bgcolor; ?&gt;">
      <td>&lt;?php echo $rnum; ?&gt;
    <td nowrap="nowrap">&lt;?php echo anchor('salesmanager/manageperson/index/'.$r->id, $r->first_name. ' ' .$r->last_name); ?&gt;</td>
    <td nowrap="nowrap">&lt;?php echo $r->email; ?&gt;</td>
    <td nowrap="nowrap">&lt;?php echo $r->phone; ?&gt;</td>
    <td nowrap="nowrap">&lt;?php echo $r->zip; ?&gt;</td>
  </tr>
  &lt;?php endforeach; ?&gt;
</table>
&lt;?php echo $this->pagination->create_links();    ?&gt;


Messages In This Thread
Please help with Pagination - SOLVED - by El Forum - 05-05-2010, 12:41 PM
Please help with Pagination - SOLVED - by El Forum - 05-05-2010, 02:51 PM
Please help with Pagination - SOLVED - by El Forum - 05-05-2010, 03:08 PM
Please help with Pagination - SOLVED - by El Forum - 05-05-2010, 03:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB