How to Retrieve Data in CodeIgniter

How to Retrieve Data in CodeIgniter

In this post i will explain how to retrieve data in codeigniter, after inserting data or records in database then next think get data or records from database. It is most important part of any application to fetch data or records using codeIgniter framework.

So I will show you how to fetch data or records from database using codeIgniter framework. 

Follow these steps

1.   First see how to insert data in CodeIgniter after that

2.   Add function in model, go to where CodeIgniter is installed path like C:\xampp\htdocs\CITest\application\models and open  employee_model.php and create a function whose name is getEmployees where employee_model is the model name and getEmployees is function inside that model.


          public function getEmployees()

         {
             $query = $this->db->get('citest_employee');
             return $query->result();
         }

3.   Some changes in Views go to where CodeIgniter is installed path like C:\xampp\htdocs\CITest\application\views and open employee_form.php where employee_form.php is the view code shown below.

          <table border="1" align="center" style="margin-top: 35px; padding:10px">
          <thead>
                 <tr>
                     <th>Emp Id</th>
                     <th>Name</th>
                     <th>Gender</th>
                     <th>Email</th>
                     <th>Phone</th>
                     <th>Address</th>
                 </tr>
          </thead>
          <tbody>
              <?php echo
                      "<tr>
                           <td>$row->emp_id</td>
                           <td>$row->emp_name</td>
                           <td>$row->emp_gender</td>
                           <td>$row->emp_email</td>
                           <td>$row->emp_phone</td>
                           <td>$row->emp_address</td>
                     </tr>"; 
              ?>
          </tbody>
          </table>


4.   Now go to browser and type localhost/CITEST/employee and insert some values and press ADD button easily you can see data are display, screen shown  below.


Retrieve Data in CodeIgniter





                        
                             I hope, it helped you to understand, how to get data from database using CodeIgniter.......Thanks

About MSK TUTORIAL

Hi...I am Md Sahjad Karim and I am Engineering Graduate (B.E in Computer Science and Engineering) working as a Web Developer and write Blog Articles. http://www.msktutorial.com/ was launched on july 2016 to provide free online hints, tips, guides and tutorials related to technology(PHP, CodeIgniter, WordPress, Blogger etc). My primary goal is to provide the good, quality and easily to understand the articles to readers around the world.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Thanks For Visiting Blog...