简体   繁体   中英

CodeIgniter: Pagination displaying links but not showing certain results per page

Hi this is a probably really obvious but I am new to pagination and I think the documentation for CI is REALLY rubbish, what I expect to get is a link list and when I click on each one it should display 3 of my li items per page, it is showing the link list and the links work, but it isn't showing a certain amount of results per page, can anybody help me with this?

My Controller section:

public function clist()
    {
        //load the model that gets a list of clients
        $this->load->model('list_model'); 
        //call the function that lists clients and store the return data in a variable
        $fields = $this->list_model->listcliname(); 
        //create an array
        $data = array();
        //assign the data to a key in the array
        $data['fields'] = $fields;
        //pass the array to view for handling and load the view.

        $this->load->library('pagination');

    $config['base_url'] = site_url('clientlist/clist');
    $config['total_rows'] = 500;
    $config['per_page'] = 3;
    $this->pagination->initialize($config);
    echo $this->pagination->create_links();

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

My View:

<html>
<head>
<title> client list </title>
<link rel="stylesheet" type="text/css" href="/css/clientlist.css">
<!--  add script to add jquery and add a function that performs a confirm on the event of a click on the delete link. --> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('.confirmation').on('click', function () {
        return confirm('Are you sure?');
    });
    });
</script>
</head>
    <body>
        <div id="container">
            <?php
            foreach($fields as $field) {
                 ?>
                 <ul>
                 <li>
                 <?php echo $field['name']; ?>
                 </li> 
                 <li>
                 <?php echo $field['contact']; ?>
                 </li>
                 <li>
                <form action="clistedit" method="post">
                <input type="hidden" name="sub" value="1" />
                <input type="hidden" name="UID" value="<?php echo $field['UID']?>">
                <button type="submit">edit</button>
                </form>
                </li>
                <li>
                <a href="/clientlist/delete/<?php echo $field['UID']; ?>/" class="confirmation">delete</a>
                <a href="/clientlist/salelead/<?php echo $field['UID']; ?>/">view lead</a>
                </li>
                </ul>
                 <?php
            }

            ?>
        </div>

EDIT: Do I have to configure somewhere what data is being paginated or does the link to the function do that?

You didn't specify which segment of your uri will contain your page_number , aka the uri_segment config of pagination.

Normally, the page number will be found at the end of your uri clientlist/clist

Your Controller code will then be:

$config['base_url'] = site_url('clientlist/clist');
$config['total_rows'] = 500;
$config['per_page'] = 3;
//Appends the page number to the url
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();

And in your view, you will have to echo the $pagination to receive the pagination links.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM