CodeIgniter Laravel PHP Example Javascript jQuery MORE Videos New
Need a Website Or Web Application Contact : +91 9437911966 (Whatsapp) Note: Paid Service

Retrieve data from database using CodeIgniter framework

In this example we will discuss about how to retrieve a record or data from MySQL database using CodeIgniter framework PHP.

For retrieve data from MySQL database using CodeIgniter framework first we have to create a table in data base.

After create a table in the MySQL database you need to insert record or data on it.If you want to know how to insert data in CodeIgniter framework please visit the link : Insert data in CodeIgniter.

The SELECT statement is used to retrieve data from one or more tables:

The SQL query for retrieve specific column.

SELECT column_name(s) FROM table_name

or we can use the * character to retrieve ALL columns from a table:

SELECT * FROM table_name

To learn more about SQL, please visit our SQL tutorial.

We use 3 file for retrieve students data.

  1. Crud.php Path: application\controllers\Crud.php
  2. Crud_model.php Path: application\models\Crud_model.php
  3. display_records.php Path: application\views\display_records.php

Sql Table

  `first_name` varchar(30) NOT NULL,
  `last_name` varchar(30) NOT NULL,
  `email` varchar(30) NOT NULL


class Crud extends CI_Controller 
  public function __construct()
  /*call CodeIgniter's default Constructor*/

  /*load database libray manually*/

  /*load Model*/
    public function displaydata()


class Crud_model extends CI_Model 
    function display_records()
    return $query->result();


<title>Display records</title>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
<table width="600" border="0" cellspacing="5" cellpadding="5">
  <tr style="background:#CCC">
    <th>Sr No</th>
    <th>Email Id</th>
  foreach($data as $row)
  echo "<tr>";
  echo "<td>".$i."</td>";
  echo "<td>".$row->first_name."</td>";
  echo "<td>".$row->last_name."</td>";
  echo "<td>".$row->email."</td>";
  echo "</tr>";

Now run the program on your browser with the below URL:


After fetch data the table look like this.

Id first name last name Email Id
1 Divyasundar Sahu
2 Hritika Sahu
3 Milan Jena