我知道如何創建分頁並生成包含codeigniter中的數據庫信息的表,但我不知道如何顯示錶中每一行的序列號。例如:如何在使用codeigniter中的表庫創建的表中顯示序列號?
SL. Name Email
1. Srijon [email protected]
2. Jake [email protected]
請您告訴我該怎麼做?在此先感謝
下面是我如何創建分頁和生成表的控制器(無序列號)
function index(){
$this->load->library('pagination');
$this->load->library('table');
$this->table->set_heading('Student ID','Student Name','Batch','Edit','Delete');
$config['base_url'] = 'http://localhost/coaching/index.php/student_list/index';
$config['total_rows'] = $this->db->get('student')->num_rows();
$config['per_page'] = 15;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div id="pagination" align="center">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['tab'] = "Student List";
$this->load->model('mod_studentlist');
$data['records']= $this->mod_studentlist->student_list();
$data['main_content']='studentlist';
$this->load->view('includes/template',$data);
}
這裏是我的模型
function student_list()
{
$config['per_page'] = 10;
$this->db->select('studentid, studentname, batch');
$this->db->order_by("studentid", "desc");
$rows = $this->db->get('student',$config['per_page'],$this->uri->segment(3))->result_array();
foreach ($rows as $count => $row)
{
$rows[$count]['studentname'] = anchor('student_list/get/'.$row['studentid'],$row['studentname']);
$rows[$count]['Edit'] = anchor('update_student/update/'.$row['studentid'],'Update');
$rows[$count]['Delete'] = anchor('report/'.$row['studentid'],'Delete');
}
return $rows;
}
這是我的看法文件
<?php echo $this->table->generate($records);?>
<?php echo $this->pagination->create_links();?>
<script type="text/javascript" charset="utf-8">
$('tr:odd').css('background','#EAEAEA');
</script>
非常感謝您的幫助。我正在獲取序列號,但它顯示在批次列下,這是假設在SL列下顯示的。請您好好看看這件事情嗎?在此先感謝:) –
我修改了代碼。使用array_unshift函數將元素添加到數組的開頭,這使序列號顯示在第一列中。 – cenanozen
非常感謝Cenanozen。它現在工作完美。 :) –