How to Fetch Data in Textarea in CodeIgniter

How to Fetch Data in Textarea in CodeIgniter

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

We will provide 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 : Fetch Data in Textarea using CodeIgniter

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

<?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

<!DOCTYPE html>
<html lang="en">
<head>
  <title>How to Fetch Data in Textarea in CodeIgniter - Web-tuts.com</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 - Web-tuts.com</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>

Output

How to Fetch Data in Textarea in CodeIgniter

I hope you understand of fetch data in textarea in codeigniter and it can help you…

Read Also :  Delete Data in CodeIgniter Example