나는 "batch"테이블의 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. 똑같은 것을 1.Bryan Adams 2. Bonjovi 3. Steve Vai와 같은 순서대로 보여 준다면. 그것은 더 좋아 보인다. 이것이 내가 원하는거야. 논리를 추측 할 수 있습니다. 데이터를 가져 오기 위해 쿼리를 만든 후에 결과에서 행 수를 계산 한 다음 루프를 수행하고 표시합니다. 당신의 도움을 주셔서 감사합니다 –