gpt4 book ai didi

mysql - codeigniter- 3 分页加载所有页面上的所有数据

转载 作者:行者123 更新时间:2023-11-29 07:38:20 25 4
gpt4 key购买 nike

我的模型

function get_all_events($limit = null, $offset = null) {

if ($limit) {

$this->db->limit($limit, $offset);
}

$this->db->order_by('events.added_on', 'desc');

return $this->db->get('events');
}

我的 Controller

public function manage_events() {


$this->securepage();

$data['events'] = $this->events_model->get_all_events();


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

$config['base_url'] = site_url('events/manage-events');

$config['total_rows'] = $this->events_model->get_all_events()->num_rows();

$config['per_page'] = 2;



$config['uri_segment'] = 3;


$this->pagination->initialize($config);




$data = array(
'news_title' => 'Manage events | kanchan news.com' ,
'Keywords' => 'manage',
'url' =>'' ,
'content'=> $this->load->view('events/manage', $data, true)
);



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

}

我的观点

<div class="container">
<ol class="breadcrumb">
<li class="active"><?php echo $this->session->userdata('full_name');?></li>
<li class="active">Manage Events</li>


</ol>
<h1>Manage Events here.</h1>

<?php echo $this->session->flashdata('msg'); ?>

<div>
<?php if ($events->num_rows()): ?>
<table class="table table-condensed">
<thead>
<tr>
<th>SN</th>
<th>Add Title</th>
<th>expire date</th>
<th>Added on</th>
<th>Action</th>
</tr>
</thead>

<tbody>

<?php foreach ($events->result() as $u): ?>
<tr>



<td><?php echo $u->id; ?></td>
<td><a href="<?php echo site_url('events/events-news/'. $u->id.'/'.$u->heading = str_replace(" ", '-', $u->heading));?>" style="text-decoration: none; color:#000;"><?php echo $u->heading = word_limiter($u->heading,10); ?></a></td>
<td><?php echo $u->venue; ?></td>
<td><?php echo date('Y-m-d | h:i:a', $u->added_on); ?></td>





<td>

<a href="<?php echo site_url('events/delete-events/'.$u->id.'/'.$u->heading = str_replace(" ", '-', $u->heading)); ?>" onclick="return confirm('Are you sure want to delete this events?')"><span class="glyphicon glyphicon-trash"></span></a>
&nbsp &nbsp <a href="<?php echo site_url('events/update-events/'.$u->id.'/'.$u->heading= str_replace(" ", '-', $u->heading)); ?>"><span class="glyphicon glyphicon-edit"></span></a>
</td>


</tr>

<?php endforeach; ?>
</tbody>
</table>

<?php else: ?>
<p>No any Events
<hr>
<a href="<?php echo site_url('events/create-events');?>" class="btn btn-danger">Add New Events</a>
</p>
<?php endif; ?>
</div>

<?php echo $this->pagination->create_links();?>


</div>

它创建分页<1 2,但它加载第1页上的所有结果,也在第2页上加载相同的结果,我尝试了很多想法,但它不起作用。我正在使用 codeigniter 3 和 mysql 。

最佳答案

发生这种情况是因为您正在获取每个页面的所有记录。您没有传递 $limit 和 $offset。在您的事件中。

$data['events'] = $this->events_model->get_all_events();//getting all records every time.

尝试像这样编写你的manage_event函数

public function manage_events($page_num=1)
{

$this->securepage();

$data['events'] = $this->events_model->get_all_events(2,($page_num-1)*2);
///keep your rest code here
//remember this 2 is from your config because you wanted view 2 record per page.You can replace it with your varible.

注意

 $config['base_url'] = site_url('events/manage-events');

这应该是

 $config['base_url'] = site_url('events/manage_events');//underscore not hypen

关于mysql - codeigniter- 3 分页加载所有页面上的所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29925945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com