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

[eluser]ChaosKnight[/eluser]
Hi, I have a database with loads of results on each return, I want to use the pagination class but I'm still unsure about how it works, the user guide is a bit vague about it...

Here is my controller function:
Code:
function display($province)
{
    $query = $this->provinces_model->getProvince($province);
    $row = $query->row();
    $province_name = $row->province;
        
    $query = $this->provinces_model->getAccommodations($province);
    $rows = $query->num_rows();
    foreach($query->result() as $row)
    {
        $data['name'][] = $row->name;
        $data['name_id'][] = $row->name_id;
        $data['type'][] = $row->type;
        $data['location'][] = $row->location;
        if(strlen($row->description) > 100)
        {
            for($i=100;$i>=0;$i++)
            {
                if($row->description[$i] == ' ')
                {
                    $short_desc = substr($row->description,0,$i);
                    break;
                }
            }
            $short_desc .= "...";
            $data['description'][] = $short_desc;
        }
        else
        {
            $data['description'][] = $row->description;
        }
        $data['image1'][] = $row->image1;
    }
        
    $data['page_title'] = $province_name;
        
    $this->load->library('pagination');

    $config['base_url'] = base_url().'index.php/provinces/'.$province;
    $config['total_rows'] = $rows;
    $config['per_page'] = '5';

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

    $this->load->view('header',$data);
    $this->load->view('nav');
    $this->load->view('sidebar');
    $this->load->view('province');
    $this->load->view('footer');
}

Here is my model function that is called in the controller:
Code:
function getAccommodations($province)
{
    $this->db->where('province_id',$province);
    $query = $this->db->get('accommodations');
    return $query;
}

As you can see I messed up with the pagination part, I really have no idea how to get started on it.. Any advice will be awesome...

Thanks
#2

[eluser]ChaosKnight[/eluser]
Fixed it... CodeIgniter is really simple once you stare at your own code for a good hour or so lol
#3

[eluser]agdelacruz02[/eluser]
Hi, can you tell me how you fixed your problem with pagination? Tnx..
#4

[eluser]Aken[/eluser]
Lol almost two years later...
#5

[eluser]phpfresher[/eluser]
Dude very good you solve the problem , but
Code:
$this->load->view('header',$data);
    $this->load->view('nav');
    $this->load->view('sidebar');
    $this->load->view('province');
    $this->load->view('footer');

I didnot like this approach of loading file
Code:
$data['template'] = 'province' ;
$this->load->view('main',$data);
And in the main file:
Code:
$this->load->view('header);
    $this->load->view('nav');
    $this->load->view('sidebar');
    $this->load->view($template);
    $this->load->view('footer');
This would be better approach and helpful to you
#6

[eluser]Mauricio de Abreu Antunes[/eluser]
Sorry, but i LOLed here. hahahaha :lol:




Theme © iAndrew 2016 - Forum software by © MyBB