2017-02-01 21 views
1

我不明白为什么发生这种情况,但每页重新加载显示同一行。我是codeigniter的新手,了解php和编程的基础知识。感谢您提前帮助。codeigniter 3.1.3分页显示相同的记录

模型:

class Clanovi_model extends CI_Model { 
    public function __construct() { 
     $this->load->database(); 
    } 

    public function get_clanovi($limit, $offset) { 
     $this->db->limit($limit, $offset); 
     $query = $this->db->get('clan'); 

     return $query->result(); 
    } 

    public function broji_clanove() { 
     return $this->db->count_all('clan'); 
    } 
} 

控制器:

class Clanovi extends CI_Controller { 

    public function index() { 

     $this->load->model('Clanovi_model'); 
     $this->load->library('pagination'); 
     $this->load->helper('url'); 

     $config['base_url'] = 'http://localhost/codeigniter5/index.php/clanovi'; 
     $config['total_rows'] = $this->Clanovi_model->broji_clanove(); 
     $config['per_page'] = 1; 

     $this->pagination->initialize($config); 
     $data['clanovi'] = $this->Clanovi_model->get_clanovi($config['per_page'], $this->uri->segment(3)); 
     $data['paginacija'] = $this->pagination->create_links(); 

     $this->load->view('zaglavlje'); 
     $this->load->view('clanovi', $data); 
     $this->load->view('podnozje'); 
    } 
} 

视图:

<h2>Članovi</h2> 
<hr> 
<table class="table table-striped"> 
<tr> 
<th>Ime</th> 
<th>Prezime</th> 
<th>Adresa</th> 
<th>Korisničko ime</th> 
<th>Lozinka</th> 
</tr> 
<?php foreach ($clanovi as $clan): ?> 

<tr> 
    <td><?php echo $clan->ime; ?></td> 
    <td><?php echo $clan->prezime; ?></td> 
    <td><?php echo $clan->adresa; ?></td> 
    <td><?php echo $clan->korisnicko_ime; ?></td> 
    <td><?php echo $clan->lozinka; ?></td> 
</tr> 

<?php endforeach; ?> 
</table> 

<?php echo $paginacija; ?> 

路线:

$route['clanovi/(:num)'] = 'clanovi/index/$1'; 
$route['clanovi'] = 'clanovi'; 

screenshot1 screenshot2

回答

0

通过寻找什么解决方案$ this-> uri-> segment(3);并将值更改为2.

$data['clanovi'] = $this->Clanovi_model->get_clanovi($config['per_page'], $this->uri->segment(2)); 
相关问题