我有一個腳本,顯示這些字段的信息 - batchname,class,批處理表中的batchinstructor。但是當我顯示數據時,我想在左側顯示動態生成的序列號。例如:如何使用mysql查詢結果顯示序列號?
Serial Number BatchName Class Batch Instructor
1. Solar Class Five John
2. Lunar Class six Bon Jovi
我試了很多,但它不工作。你能否幫我解決這個問題?請注意,這些序列號不是來自數據庫。
這裏是我的控制器:
<?php
class Batchlist extends CI_Controller{
function index(){
$this->load->library('pagination');
$config['base_url'] = base_url().'batchlist/index';
$config['total_rows'] = $this->db->get('batch')->num_rows();
$config['per_page'] = 20;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div class="pagination" align="center">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$this->load->model('mod_batchlist');
$data['records']= $this->mod_batchlist->batch_list($config['per_page'],$this->uri->segment(3));
$data['main_content']='view_batchlist';
$this->load->view('includes/template',$data);
}
} >
這裏是我的模型:
function batch_list($perPage,$uri) {
$this->db->select('*');
$this->db->from('batch');
$this->db->join('teacher', 'batch.batchinstructor = teacher.teacherid');
$this->db->order_by('batchid','DESC');
$getData = $this->db->get('', $perPage, $uri);
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
這裏是我查看
<h1>Batch List </h1>
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>Batch Name</th>
<th>Class</th>
<th>Batch Instructor</th>
<th>Edit/Delete</th>
</tr>
</thead>
<tbody>
<?php foreach ($records as $row){ ?>
<tr>
<td><a href="<?php echo base_url(); ?>batch/<?php echo $row['batchid']; ?>"><?php echo $row['batchname'];?></a></td>
<td><?php echo $row['class'];?></td>
<td><?php echo $row['teachername'];?></td>
<td> <a href="<?php echo base_url(); ?>updatebatch/get/<?php echo $row['batchid']; ?>" title="Edit"><img src="<?php echo base_url(); ?>support/images/icons/edit.png" alt="Edit" /></a>
<a href="#" title="Delete"><img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" /></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="tablefooter clearfix">
<div class="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
實際上,當您顯示數據時,您可能想按照列出的順序顯示數據。例如,你寫了一些名字像Bryan Adams,Bon Jovi,Steve Vai。但是,如果你按照列出的順序顯示這個相同的東西,比如1. Bryan Adams 2. Bonjovi 3. Steve Vai。它看起來更好。這就是我要的。我可以猜出這個邏輯,那是在查詢獲取數據之後,你計算結果中的行數,然後做一些循環和顯示。謝謝你的幫助 –