Codeigniter 2.2分页没有显示

时间:2013-01-24 05:47:31

标签: codeigniter pagination

尝试一小时但不工作。我可以在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(); ?>

1 个答案:

答案 0 :(得分:1)

问题在于此

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

您无法使用$query->num_rows();,因为这总是返回2行 您应该有另一个查询来获取实际查询的总行数,
应该是SELECT COUNT(*)