Codeigniter 2.2页码未显示

Codeigniter 2.2页码未显示,codeigniter,pagination,Codeigniter,Pagination,尝试一个小时,但不工作。我可以手动切换URL中的/welcome/index/1或2或3。只是该死的分页没有显示 我的控制器 $offset = $this->uri->segment(3,0); $query = $this->db->query( 'SELECT p.id AS pid, p.url, p.created_time,

尝试一个小时,但不工作。我可以手动切换URL中的/welcome/index/1或2或3。只是该死的分页<1 2 3 4>没有显示

我的控制器

        $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(); ?>

问题在于此

$config['total_rows'] = $query->num_rows();
您不能使用
$query->num_rows(),因为这总是返回2行。
您应该有另一个查询来获取实际查询的总行数,
哪个应该是
SELECT COUNT(*)