0
排序數據嘿傢伙我是codeigniter中的新手,我正在從事數據庫工作,我有一個表feuhed ..我想排序表通過點擊表頭我怎麼能做到這一點。 。我使用的是這樣的代碼: -通過點擊列標題來逐列排序數據,並通過再次點擊使用codeigniter
控制器:
function index()
{
$config['total_rows'] = $this->db->get('tbl_members')-> num_rows();
$config['per_page'] = 2;
$segment_array=$this->uri->segment_array();
$segment_count=$this->uri->total_segments();
$do_orderby = array_search("orderby",$segment_array);
$asc = array_search("asc",$segment_array);
$desc = array_search("desc",$segment_array);
$this->db->order_by($this->uri->segment($do_orderby+1), $this->uri->segment($do_orderby+2));
if (ctype_digit($segment_array[$segment_count]))
{
$data['page']=NULL;
$this->db->limit($config['per_page']);
}
else
{
$data['page']=$segment_array[$segment_count];
$this->db->limit($config['per_page'], $segment_array[$segment_count]);
array_pop($segment_array);
}
$config['base_url'] = site_url(join("/",$segment_array));
$config["uri_segment"] = count($segment_array)+1;
$this->load->model('mod_user'); //load the mod_user class
$data['rows'] = $this->mod_user->getmembers();
//initialize pagination
$this->pagination->initialize($config);
$this->load->view('view_home',$data);
$this->load->view('view_homemember',$data);
}
我的看法是:
<form class="userinfo" action="" method="post">
<?php //if(count($rows) > 0) { ?>
<table border="1" cellpadding="2" cellspacing="0">
<?php
// For Sorting
//default in descending order
$sort['col1']='desc';
$sort['col2']='desc';
$sort['col3']='desc';
//get the segment array
$segment_array=$this->uri->segment_array();
//search for the orderby string
$do_orderby = array_search("orderby",$segment_array);
//check to toggle asc and desc sorting in columns
if($do_orderby !== FALSE) {
$sort[$segment_array[$do_orderby+1]]= $segment_array[$do_orderby + 2] == 'desc' ? 'asc' : 'desc' ;
}
?>
<tr>
<td width="5%;"> </td>
<td width="5%;"> </td>
<td width="15%;"><?php echo "<a href=\"".site_url()."/ctl_home/index/member_name/{$sort['col1']}/".$page."\">";?>Name</a></td>
<td width="15%;">Moderator Name</td>
<td width="20%;">KCC Branch</td>
<td width="15%;">Father/Husband Name</td>
<td width="15%;">Address</td>
<td width="10%;">Date</td>
</tr>
我相信教程指的是一個很老的(現在的)CI版本th ough;我經常看到這個系列作爲答案,我認爲它公平地指出它的年齡 – 2013-03-15 08:04:52
我已經看到了這個教程@jonixj – Jay 2013-03-15 10:21:33