Try for hour but not working. I can manually switching the /welcome/index/1 or 2 or 3 in the URL. Just the damn pagination < 1 2 3 4 > not showing !
My controller
$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;
Then in my html
<?php echo $this->pagination->create_links(); ?>
The problem is lied on this
You can’t use the
$query->num_rows();, as this is always return 2 rows.You should have another query to get the total rows for the actual query,
which should be a
SELECT COUNT(*)