Jump to content

How to display Serial Numbers with mysql query result in codeigniter?


srijon

Recommended Posts

Hi, I am trying to fetch data from my database and when I display it I want to show serial numbers (Just like a list) , example:

 

Serial Number      Name          Country

  1.                      John            USA

  2.                     Srijon            UK

 

I have tried something with PHP Loops, but I couldn't make it work. Would you please kindly help me? please note that by serial numbers I don't mean values retrieved from database.

 

Thanks in Advance :)

 

Here's my Model

 

//Function To Create All Batch List
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;
	}
	//End of Function To Create All Batch List

 

Here's my 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);

}

 

Here's my View

 

<?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>

 

 

 

 

So what exactly do you mean by serial?  Are you just trying to number them down? If so then use a counter like this:

 

<thead>
<tr>
                <th>Serial</th>
	<th>Batch Name</th>
	<th>Class</th>
	<th>Batch Instructor</th>
	<th>Edit/Delete</th>
</tr>
</thead>

<tbody>
                <?php $cnt = 1; ?>
	<?php foreach ($records as $row){ ?>
<tr>
                <td><?php echo $cnt; $cnt++;?></td>
	<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  } ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.