Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用分页| CodeIgniter|_Php_Mysql_Codeigniter_Pagination - Fatal编程技术网

Php 如何使用分页| CodeIgniter|

Php 如何使用分页| CodeIgniter|,php,mysql,codeigniter,pagination,Php,Mysql,Codeigniter,Pagination,我有一个查询来显示我网页上的所有用户。 我们有大约327个用户。我想使用分页。但是我不知道如何在我自己的代码中使用它 这是我的控制器 <?php class alluser extends MY_Controller { function __construct() { parent::__construct(); $this->load->helper('date'); $this->load-&

我有一个查询来显示我网页上的所有用户。 我们有大约327个用户。我想使用分页。但是我不知道如何在我自己的代码中使用它

这是我的控制器

<?php


class alluser extends MY_Controller {



    function __construct() {


        parent::__construct();

        $this->load->helper('date');

        $this->load->helper('file');

        $this->load->helper('dir');

        $this->load->model('user_model');

        $this->load->model('inspiration_model');

        $this->load->model('notes_model');

        $this->load->library('pagination');
        $config['total_rows'] = 300;
        $config['per_page'] = 20;
        $this->pagination->initialize($config);
        echo $this->pagination->create_links();

        $this->data['head']['stylesheets'][] = 'onestowatch/onestowatch.min.css';

        $this->data['head']['javascripts'][] = 'shuffle/jquery.shuffleLetters.min.js';

        $this->data['head']['javascripts'][] = 'custom/app/onestowatch.min.js';

        if (!logged_in()) {

            redirect('login');

        }

    }


   public function index(){

    $user_id = $this->data['user']['user_id'];

    $now = time();



    $designments = $this->user_model->get_my_running_designments_by_id($user_id, $now);



    foreach ($designments as &$designment) {

        $designment['inspiration_count'] = $this->inspiration_model->get_inspiration_count_for_user_by_id($designment['designment_id'], $user_id);

        $designment['note_count'] = $this->notes_model->get_notes_count_for_user_by_id($designment['designment_id'], $user_id);

    }



    $this->data['my_designments'] = $designments;



    $this->data['user_info'] = $this->user_model->get_user_info_by_user_id($user_id);

    $this->data['user_info']['user_icon'] = $this->user_model->get_big_user_icon_by_id($user_id);

    $this->data['onestowatch'] = $this->user_model->get_ones_to_watch(1000);

    $this->template->load('templates/template_view', 'app/alluser/view', $this->data);

}

谢谢你给我的每一个帮助

您可以参考下面的链接创建分页

我已经编写了关于Cdeigniter分页的教程。请看一看并给出你的建议
<script type="text/javascript">
    var onestowatch = <?= json_encode($onestowatch) ?>;
</script>

<section id="list" class="w940 fl">
    <p class="clearfix"><span class="bg-white ff-b orange f28 title-1 fl shadow">All users</span></p>
</section>


<script type="text/x-mustache" id="onetowatch">
    <dl style="margin-top: 20px;">
    <dd>
    <div class="onetowatch shadow">
    <img class="user_icon" src="<?= site_url('') ?>{{image}}">
    <div class="fl ff-l f18 shuffle">{{fullname}}</div>
    </div>
    </dd>
    </dl>
</script>
function get_ones_to_watch($limit, $smallicon = false) {
        $this->db->select('user_to_designment.user_id, count(user_to_designment.user_id) as designment_joined, user_profiles.first_name, user_profiles.middle_name, user_profiles.last_name, user_profiles.date_of_birth');
        $this->db->from('user_to_designment');
        $this->db->join('user_to_user_profile', 'user_to_designment.user_id = user_to_user_profile.user_id');
        $this->db->join('user_profiles', 'user_to_user_profile.profile_id = user_profiles.profile_id');
        $this->db->group_by('user_id');
        $this->db->order_by('designment_joined', 'desc');
        $this->db->limit($limit);

        $onestowatch = $this->db->get()->result_array();

        foreach ($onestowatch as &$onetowatch) {
            if($smallicon){
                $onetowatch['image'] = self::get_small_user_icon_by_id($onetowatch['user_id']);
            }else{
                $onetowatch['image'] = self::get_big_user_icon_by_id($onetowatch['user_id']);
            }
        }

        return $onestowatch;
    }