user3839366
user3839366

Reputation: 9

How to display Tamil content form mysql database in codeigniter

I am having problem for viewing the Tamil content which retrive from mysql database using CodeIgniter. but the same code is working in core php. i have attached my code below. please check my code and give answer if any changes.

this is my view code:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <table class="table table-striped table-bordered table-hover dataTables-example" >
                <thead>
                <tr>
                    <th>Title</th>
                    <th>Description</th>
                 </tr>
                </thead>
                 <tbody>
                          <?php

                               foreach ($per_results as $result)
                               {

                               ?>
    <tr class="">

                               <td><?php echo $result->title;?></td>
                               <td><?php echo $result->description;?></td>
   </tr>
    <?php
                               }
                               ?>

                          </tbody>

                </table>

This is my Controller COde:

   public function view_mainhome()
    {
      $data['per_results'] = $this->Login_model->getview_permission();
      $this->load->view('forest_add/view_mainhome',$data);
    }   

This is my Model Code:

        function getview_permission() //Stock
        {   
        $this->db->select('*');
        $this->db->from('forest_permission');
        $this->db->order_by("per_id", "asc");
        $query = $this->db->get();
         return $query->result();
        }

Thanks @

Upvotes: 0

Views: 3636

Answers (4)

Jegan S
Jegan S

Reputation: 27

using following mysqli function to we can achieve this 100% worked

 config['set_charset']=array( $db, 'utf8');

replace $db instead your db connection variable.

Upvotes: 1

j-bin
j-bin

Reputation: 691

@user3839366 utf8_general_ci is the collation, make sure you have the same collation for other table fields which you join and compare.

I'm leaving this for anyone else having the utf8 issues. If you have unicode characters, you can do this while creating the table,

CREATE TABLE `your_table_name` (
....
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

or later

ALTER TABLE `your_table_name` CONVERT TO CHARACTER SET utf8;

with specific collation

CREATE TABLE `your_table_name` (
....
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;

or later

ALTER TABLE `your_table_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

note:- You can use utf8mb4 if you want full unicode support (eg, store an emoji in your db)

Also if you want to see the result in console, run set names utf8; (also for programs or scripts that do not have out of the box unicode support)

Upvotes: 0

Geordy James
Geordy James

Reputation: 2398

As per my comment,

Change datatype of SQL column to utf8_general_ci

Upvotes: 1

bikram kc
bikram kc

Reputation: 876

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

Please try this code in your document header. I hope this will work for Tamil language.

Upvotes: 1

Related Questions