How to retrieve data from mysql and display in codeigniter view?
As you all are know codeigniter is an MVC framework, now by using model, view and controller we will retrieve data from mysql table and display in codeigniter view.
I had taken a small table with firstname, lastname and emailed. Now I will create a controller function. Here from below diagram you will get an overview how Model, view and controller works.
Now create controller file under applications/controller/welcome.php ,open the controller file copy
below code there.
Now let’s check model file, create file under applications/model/ektreemodel.php.
Open the file and copy below code in the model file.
Now finally create a view under applications/views/fetchdata.php,Open the file and copy the below code in view.
Now finally open the xampp and start apache and mysql servers. And then go to browser and type localhost:/projectname/index.php/controller_name/function_name
Now you will get output as below…
Thanks for reading this article ,feel free to post your comments below for any issues.