Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6607605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:31:16+00:00 2026-05-25T19:31:16+00:00

I know how to create pagination and generate a table containing information from database

  • 0

I know how to create pagination and generate a table containing information from database in codeigniter, but I don’t how to display the serial numbers for each row in the table. Example:

SL.  Name           Email
1.  Srijon      example@yahoo.com
2.  Jake        jake@yahoo.com

Would you please kindly show me how to do that? Thanks in advance

Here is the controller for how I create pagination and generate table (without serial numbers)

 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);

        }   

Here’s my model

                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;
    }

Here’s my view file

                 <?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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:31:17+00:00Added an answer on May 25, 2026 at 7:31 pm

    You should create a variable inside your model function:

    <?php
    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();
    
        $sl = $this->uri->segment(3) + 1; // so that it begins from 1 not 0
    
        foreach ($rows as $count => $row)
            {
             array_unshift($rows[$count], $sl.'.');
             $sl = $sl + 1;
    
             $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;
    }
    

    and modify your controller:

    <?php
    function index() {
        $this->load->library('pagination');
        $this->load->library('table');
        $this->table->set_heading('SL.', 'Student ID','Student Name','Batch','Edit','Delete');
        ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know the statement: create table xyz_new as select * from xyz; Which copies
I know how to create a SEL at compile time using @selector(MyMethodName:) but what
I know how to create a custom user control in WPF but how can
i kinda know how to create a Custom Web Part. But now i need
I think I know how to create custom encrypted RSA keys, but how can
I know I could write scripts and create jobs to run them, but at
I know how to use JSON to create objects, but there doesn't seem to
I know how to create a list template by creating from an existing list.
I don't know how to create a regular expression in JavaScript or jQuery. I
Anyone know how to create a routed event in Silverlight 2? In WPF, the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.