2013-01-24 49 views
0

嘗試小時,但不工作。我可以手動切換URL中的/ welcome/index/1或2或3。只是該死的分頁< 1 2 3 4>不顯示!Codeigniter 2.2分頁沒有顯示

我控制器

 $offset = $this->uri->segment(3,0); 

    $query = $this->db->query(
     'SELECT p.id AS pid, 
       p.url, 
       p.created_time, 
       t.name, 
       t.num_photo, 
       t.id AS tid 
     FROM photos p 
     LEFT JOIN tag_maps AS tm ON p.id = tm.photo_id 
     LEFT JOIN tags AS t ON t.id = tm.tag_id 
     INNER JOIN 
     (
      SELECT MAX(created_time) maxDate, t.id 
      FROM photos p 
      LEFT JOIN tag_maps AS tm ON p.id = tm.photo_id 
      LEFT JOIN tags AS t ON t.id = tm.tag_id 
      GROUP BY t.id 
     ) AS d 
     ON p.created_time = d.maxDate 
     AND t.id = d.id 
     ORDER BY p.created_time LIMIT ' . $offset . ',2' 
    ); 
    $config['base_url'] = 'http://localhost:8080/example/welcome/index'; 
    $config['total_rows'] = $query->num_rows(); 
    $config['per_page'] = 2; 
    $config['num_links'] = 20; 
在我的HTML

然後

<?php echo $this->pagination->create_links(); ?> 

回答

1

的問題上撒謊這

$config['total_rows'] = $query->num_rows(); 

您不能使用$query->num_rows();,因爲這始終是回報2排。
你應該有另一個查詢得到總行的實際查詢,
這應該是一個SELECT COUNT(*)

+0

明白了,非常感謝 – vzhen