0

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

1 回答 1

1

问题出在这

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

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

于 2013-01-24T05:53:45.180 回答