Join Query Using Codeigniter


In This tutorial will help you to learn join query using php codeigniter. Table joins are essential part in application development while displaying the records from multiple tables. So lets have a closer look.

Tools and Technologies

To execute Php codeigniter Application I have used below technologies.

  1. Php Codeigniter 1.7.3
  2. XAMPP / Php 5.2.3
  3. Mysql 5.0.4

trn_employee table

Create two tables trn_employee and trn_address table with the help of below mysql scripts and few records in both the tables, but make sure that there should be join association between tables with common field.

trn_address table

Address table contains employee address.

Codeigniter Database Configuration

As you know that Php Codeigniter is popular for minimum configuration (almost Zero configuration) framework. To connect to database you need to provide username, password and database name configuration details in database.php file.

The config file is located at "application/config/database.php". Like in my case my local mysql database setting is as below.

Codeigniter Base Url Configuration


Lets creates the Controller class called Home.php under folder name application/controllers along with default method name index().

Join Syntax

You can specify the JOIN type also , use the third optional parameter of the function. like left, right, outer, inner, left outer, and right outer etc


Lets create the Model class which will query the database tables and get the records. Navigate to the folder application/models of your codeigniter application and create a new php file called HomeModel.php

Define the getEmployees() method, which reads the records from trn_employee and trn_address table.


Lets create index.php file under folder name application/views. Here we are going to display the employee and address information.


Enter the url http://localhost/codeigniterexamples in your browser, It will display the employee details

Leave A Reply

Your email address will not be published.