Retrieve data from the Database

Now we will discuss how we can retrieve data from the database that we have inserted to the employees table of the database in our previous topic “inserted data to the database”.

Retrieve data from Database

The following are the records of the employees table that we have to retrieve in our CodeIgniter application.

     To get the above records, we need to create the following files, as shown below:

Create a controller file Employee_controller.php and save it in application/controller/Employee_controller.php. And write the following program in the controller file.

Employee_controller.php

Create a model file Data_Model.php and save it in application/model/Data_Model.php. And write the following program in the model file.

Data_Model.php

Create a view file fetch.php and save it in application/views/fetch.php. And write the following program in the controller file.

fetch.php

To run the program in the localhost by invoking the URL localhost/CodeIgniter-3.1.11/index.php/Employee_controller function; it shows the output as shown below.

Retrieve data from Database

Pin It on Pinterest

Share This