php - Pagination error url was not found


I created a Pagination in Codeigniter, because I would like 2 news in one page and 2 news other page etc...

So, here is my Model:

class Country extends CI_Model
    public function __construct() {

public function record_count() {
    return $this->db->count_all("news");

public function fetch_countries($limit, $start) {
    $this->db->limit($limit, $start);
    $query = $this->db->get("news");

    if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            $data[] = $row;
        return $data;
    return false;

I can see my news. My problem is if I want to move to the next page, I will get an error that url was not found welcome/index/2 (its the second page). localhost/codeigniter/ -> this is my homepage and the news are revealed on the homepage. It is possible to see the news but when I want to scroll to the next page then it gives the error.


  public function __construct()

public function index()
    $config = array();
    $config["base_url"] = base_url() . "welcome/index";
    $config["total_rows"] = $this->Country->record_count();
    $config["per_page"] = 2;
    $config["uri_segment"] = 3;


    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data["results"] = $this->Country->
        fetch_countries($config["per_page"], $page);
    $data["links"] = $this->pagination->create_links();

    $data['news'] = $this->news_model->get_news();
    $data['title'] = 'News archive';

    $this->load->view('index', $data);


And finally the View:

foreach($results as $data) {
echo $data->title . " - " . $data->text . "<br>";

I hope I was clear, but if not, then please ask, and I will edit the question.




Your code seems fine my guess you did not configure your routes. The URI Guide

 $route['welcome/(:any)'] = 'welcome/index/$1';

If you just have welcome that will detect index function

 $config["base_url"] = base_url('welcome'); 

Base Url

 $config['base_url'] = 'http://localhost/codeigniter/';

People are also looking for solutions to the problem: php - laravel 5.1 localization not working


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.