In this example, we will show how to fetch data in textarea in codeigniter. We will how to fetch data from the database in textarea using Codeigniter. You can learn to fetch data in textarea with codeigniter.

We will provide a simple example of how to fetch data from textarea in Codeigniter. After read this post you can simply fetch data in your textarea using Codeigniter.



Example 

Create Controller

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

class DemoController extends CI_Controller {
    function __construct() {
        parent::__construct();
        $this->load->model('demo');
    }
    
    function demo(){
        $data['demo'] = $this->demo->get_row_by_id('demo', array("id"=>1));
        $this->load->view('demo',$data);
    }
}


Create Model

create Demo model 

<?php

class Demo extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function get_row_by_id($table_name,$where_array){
        $this->db->select("*");
        $this->db->from($table_name);
        $this->db->where($where_array);
        $query = $this->db->get();
        if ($query->num_rows() > 0){
            return $query->row();
        }else{
            return false;
        }
    }
    
}

Create View

create demo view

<!DOCTYPE html>
<html lang="en">
<head>
  <title>How to Fetch Data in Textarea in CodeIgniter</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>How to Fetch Data in Textarea in CodeIgniter</h2>

  <form method="post">

    <div class="form-group">
      <label for="message">Message:</label>
      <input type="hidden" name="id" value="<?= $demo->id ?>">
      <textarea class="form-control" id="message" placeholder="Enter message" name="message"><?= $demo->message ?></textarea>
    </div>
    
    <button type="submit" class="btn btn-primary">Update</button>
  </form>
</div>

</body>
</html>

Thanks may this example help you.....