有人用排序进行php codeigniter分页吗?
我在php codeigniter工作。我使用了分页,但是如何像数据表分页一样对字段数据进行排序。请帮助我在视图顶部添加以下代码有人用排序进行php codeigniter分页吗?,php,codeigniter,pagination,Php,Codeigniter,Pagination,我在php codeigniter工作。我使用了分页,但是如何像数据表分页一样对字段数据进行排序。请帮助我在视图顶部添加以下代码 $page = (int)$this->uri->segment(3); if($page==0) { $page=1; } $order_seg = $this->uri->segment(5,"asc"); $order= ($order_seg == "asc") ? "desc" : "asc"; 使用以下表格标题 <th&
$page = (int)$this->uri->segment(3);
if($page==0) { $page=1; }
$order_seg = $this->uri->segment(5,"asc");
$order= ($order_seg == "asc") ? "desc" : "asc";
使用以下表格标题
<th><a href="<?php echo base_url().'test/view/'.$page.'/f_name/'.$order; ?>">First Name</a></th>
然后像这样把这个传给你的模特
$data['result']=$this->test_Model->view((($page-1)*$config['per_page']),$config['per_page'],$sort,$order);
希望在申请上述职位后,这将起作用 尝试在查询中使用ASC或DESC order子句。您的数据将被排序 在视图中,标记形式之间:
<!--Código para capturar la ordenación-->
<input type="hidden" id="orderby" name="orderby" value="<?php if (isset($orderby)) echo $orderby; ?>">
<input type="hidden" id="tipoOrderby" name="tipoOrderby" value="<?php if (isset($tipoOrderby)) echo $tipoOrderby; ?>">
在Codeigniter控制器中:
if($form_data['orderby'] == ""){ //Default sort
$orderby = "name";
$tipoOrderby = 'ASC';
}
else{
$orderby = $this->input->post('orderby');
$tipoOrderby = $this->input->post('tipoOrderby');
}
//Returns values view
$data['orderby'] = $orderby;
$data['tipoOrderby'] = $tipoOrderby;
最后,您应该将其包括在查询模型中=)
有任何疑问吗?此链接可能有助于使用引导数据表
<thead>
<tr>
<th> Column 1 <a href="#" data-type="order" data-field="column1"><i class="fa fa-sort"></i></a></th>
<th> Column 2 <a href="#" data-type="order" data-field='column2'><i class="fa fa-sort"></i></a></th>
</tr>
</thead>
// Código para controlar la ordenación de la tablas
$(document).find('a[data-type="order"]').each(function () {
if ($(this).data("field") == document.form1.orderby.value) {
if (document.form1.tipoOrderby.value == "ASC") {
$(this).data("order", "DESC");
$("i", this).addClass('fa-sort-desc');
} else {
$("i", this).addClass('fa-sort-asc');
$(this).data("order", "ASC");
}
} else {
$("i", this).addClass('fa-sort');
$(this).data("order", "ASC");
}
$(this).click(function (event) {
event.preventDefault();
document.form1.orderby.value = $(this).data("field");
document.form1.tipoOrderby.value = $(this).data("order");
document.form1.submit();
});
});
if($form_data['orderby'] == ""){ //Default sort
$orderby = "name";
$tipoOrderby = 'ASC';
}
else{
$orderby = $this->input->post('orderby');
$tipoOrderby = $this->input->post('tipoOrderby');
}
//Returns values view
$data['orderby'] = $orderby;
$data['tipoOrderby'] = $tipoOrderby;
$query = $this->model->get($pages, $this->uri->segment($config['uri_segment']), $where, $orderby, $tipoOrderby);