CodeIgniter Forums
Pagination issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Pagination issue (/showthread.php?tid=35293)



Pagination issue - El Forum - 10-25-2010

[eluser]Unknown[/eluser]
UPDATE: now the page seems to be working.

BUT not the URL. point is that having 25 tot rows in a table, last page will be page/pag/24 instead page/pag/25 because the first page is page/pag/0
I need to show one result per page,that's it.

Thanks for any help. (?)

Code:
autoload.php

$autoload['libraries'] = array('database', 'session', 'pagination','xmlrpc');
$autoload['helper'] = array('file', 'url', 'recaptcha', 'template_inheritance');

Code:
routes.php

$route['default_controller'] = "page/pag";

in config.php I get

$config['index_page'] = "";

UPDATE:it was mostly an htaccess issue

Code:
htaccess:

RewriteEngine On
    RewriteBase /vinyl

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

[code]model: conf.php

<?php

class Conf extends Model {
    
    function conf()
    {
        // Call the Model constructor
        parent::Model();
    }

    function tot()
    {
        $q = $this->db->get('canzoni');
        return $q->result();
    }

    function one()
    {
        $one = $this->db->get('canzoni', 1);
        return $one->result();
    }
    
    // get records from database
    
function get($offset = NULL, $num_per_page = NULL)
{
  $this->db->from('canzoni');

  if (isset($offset) && isset($num_per_page)) {
    $this->db->limit($num_per_page, $offset);
  }

  return $this->db->get()->result();
}

        
    function row_count()
    {
        return $this->db->count_all('canzoni');
    }
    
    function ua(){
        if ($this->agent->is_browser())
        {
            $agent = $this->agent->browser().' '.$this->agent->version();
        }
        elseif ($this->agent->is_robot())
        {
            $agent = $this->agent->robot();
        }
        elseif ($this->agent->is_mobile())
        {
            $agent = $this->agent->mobile();
        }
        else
        {
            $agent = 'Unidentified User Agent';
        }

        echo $agent;

    }

// end class

}

?>


Code:
controller: page.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Page extends Controller {

    function Page(){
        parent::Controller();
    }

    function index()
    {
        $this->pag();
    }

    function pag($offset = 0, $page = 'home')
    {
        $this->load->model('conf');
        $data = array();
        $data['titolo'] = 'Discografia vinile';
        $data['si'] = $session_id = $this->session->userdata('session_id');
        $data['info'] = $this->benchmark->elapsed_time();

        // Pagination
        $num_per_page = 1;
        $tot_rows = $this->conf->row_count();
        
        $config['base_url'] = site_url('page/pag/');
        $config['total_rows'] = $tot_rows;
        $config['per_page'] = $num_per_page;
        $config['first_link'] = 'Prima pagina';
        $config['first_tag_open'] = '<li>';
        $config['last_link'] = 'Ultima pagina';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['next_link'] = 'Next >';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['prev_link'] = '< Back';
        $config['prev_tag_open'] = '<li>';
        $config['full_tag_open'] = '<ul class="navrecords">';
        $config['full_tag_close'] = '</ul>';
        $config['cur_tag_open'] = '<li>';
        $config['cur_tag_close'] = '</li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        
        $data['records'] = $this->db->get('canzoni',$num_per_page,$offset)->result();
        print 'offset:'. $offset;

        $this->load->view('pages/'.$page, $data);
    }

}

?&gt;

Code:
view: views/pages/home.php

&lt;?php extend('master_template.php');

    startblock('listapag');
    
echo $this->pagination->create_links();
print '<p>last query:'.$this->db->last_query().'</p>'; ?&gt;

    <dl>
        &lt;?php foreach($records as $row) { ?&gt;
        <dt>&lt;?php echo $row->autore; ?&gt;</dt>
        <dd>&lt;?php echo $row->titolo; ?&gt;
        <ul>
            <li>&lt;?php echo $row->anno; ?&gt;</li>
            <li>&lt;?php echo $row->Label; ?&gt;</li>
            <li>ID: &lt;?php echo $row->id; ?&gt;</li>
        </ul>
        </dd>
        
        
        &lt;?php }; ?&gt;
    </dl>
    &lt;?php //echo $this->pagination->create_links(); ?&gt;
        <p class="data">Totale titoli presenti: <strong>&lt;?php echo $this->conf->row_count(); ?&gt;</strong></p>
        <p>Page generated in <strong>&lt;?php print $info; ?&gt;</strong></p>
    
    &lt;?php endblock();

end_extend(); ?&gt;