How to display data codeigniter

Create a view file display.php and save the below code it in application/views/display.php.

<!DOCTYPE html>
<html lang="en">
  <title>Display Data</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>
  <script src=""></script>

<div class="container">         
  <table class="table table-hover">
            foreach($data as $d){
        <td><?php echo $d->id; ?></td>
        <td><?php echo $d->name; ?></td>
        <td><?php echo $d->email; ?></td>


Create a controller file Demo.php and save it in application/controller/Demo.php.

defined('BASEPATH') OR exit('No direct script access allowed');

class Demo extends CI_Controller {
    public function __construct() {
    function insert(){
    function save(){
        $data = $this->input->post();
        $result = $this->Demo_Model->save("demo",$data);
        if (!empty($result)){
    function display(){
        $data["data"] = $this->Demo_Model->get_all("demo");

Create a model file Demo.php and save it in application/models/Demo_Model.php.


class Demo_Model extends CI_Model{
    function save($table_name,$data){
        return $this->db->insert_id();
    function get_all($table_name){
        $query = $this->db->get();
        return $query->result();

Let us execute this example by the following URL in the browser. This URL may be different based on your website.