我有一个查询来显示我网页上的所有用户。 我们有大约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);
}
这是我的观点:
<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;
}
感谢您的一切帮助!