srijon Posted October 30, 2011 Share Posted October 30, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/250111-how-to-display-serial-numbers-with-mysql-query-result-in-codeigniter/ Share on other sites More sharing options...
jotorres1 Posted November 1, 2011 Share Posted November 1, 2011 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/250111-how-to-display-serial-numbers-with-mysql-query-result-in-codeigniter/#findComment-1283973 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.