How to fetch data in CodeIgniter

In previous tutorial we learned how to insert data into data in CodeIgniter. In this tutorial we will learn how to fetch data from database in CodeIgniter.
1.Create a model(Read_data_Model.php) inside application/mode

Class Read_data_Model extends CI_Model{
public function readdata(){
		        return $query->result();

2.Create a controller(Read_data.php) inside application/controller

Class Read_data extends CI_Controller{
public function index(){
//load model
//load model function
//loading view with passing result array

3. Create a view (read_data.php)  inside application/view

<table class="table table-responsive">
<th>Email id</th>
<th> Mobile Number</th>
<th> Gender</th>
<th> Address</th>
<th> Terms and Conditions</th>
<th>Posting date</th>
if(count($result)) {
foreach ($result as $row){
<td><?php echo htmlentities($cnt);?></td>
<td><?php echo htmlentities($row->fullName)?></td>
<td><?php echo htmlentities($row->emailId)?></td>
<td><?php echo htmlentities($row->mobileNumber)?></td>
<td><?php echo htmlentities($row->gender)?></td>
<td><?php echo htmlentities($row->address)?></td>
<td><?php echo htmlentities($row->address)?></td>
<td><?php echo htmlentities($row->postingDate)?></td>
} // end foreach
} else { ?>
<td colspan="7">No Record found</td>


View Demo

How to run this script

  1. Download the zip file .
  2. Extract the zip and copy registrationci folder
  3. Paste in root directory(For xampp htdocs and for wamp www)
  4. Open your browser put http://localhost/phpmyadmin
  5. Create a database cidb
  6. Import sql file tblusers.sql
  7. Run your script http://localhost/registrationci

How to fetch data in CodeIgniter (Download Script)
Size: 2.75 MB
Version: V 1

Recommended Tutorials for you

Related posts

CodeIgniter Controllers

Anuj Kumar

CodeIgniter Plugins

Anuj Kumar

CodeIgniter Interview Questions and Answers

Anuj Kumar

CRUD operation in CodeIgniter

Anuj Kumar

CodeIgniter View

Anuj Kumar

Database interaction in CodeIgniter

Anuj Kumar

Form Validation in CodeIgniter

Anuj Kumar

Validation rules to a config file in CodeIgniter

Anuj Kumar

CodeIgniter Model

Anuj Kumar


khan November 30, 2018 at 5:50 pm

could you plz guide me….about relationship ….how to make relationship between tables…using php myadmin

Anuj Kumar December 2, 2018 at 7:19 am

Use foreign key for relation


Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.