CodeIgniter – Read

CodeIgniter – Read

Today, I will show you how to get results from database and print in in table.

This is very common operation and it is not to complicated, especially when using CodeIgniter’s Active Record for database communication.

In case you missed our previous tutorial with adding records to database, you can find it on the link bellow

CodeIgniter – Insert Tutorial

Lets start our lesson 2, CodeIgniter – Read


We need to modify our Site controller’s index function because we use it for displaying our results.

We will store results from our model into $data array that we’ll pass to the view.




We need a new function that will get data we submitted to database.

So, we added a new function called get that returns data from components table.




We’ll now modify site.php view and add a table that will contain our results.

Every result will be shown in new table row.

In case that components table is empty, it will print that there are no added components.



Now when we go to our CodeIgniter’s homepage, we’ll see results read from database.


Go to New Component and add a few more components, it will look like this


That concludes our Lesson 2 – CodeIgniter – Read

Stay tuned for the next lesson where we will edit some values from database.

You can download complete source code from this lesson on the link bellow

CodeIgniter Lesson 2 РRead

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *