php - Order Arabic data by alphabet letters -


how can order data grabbed mysql arabic alphabet ?

note: use utf8_general_ci collation in mysql, , encoding fine, want know how sort data alphabet.

in order sort arabic text in mysql database using php, have make sure that:

  1. mysql charset: utf-8 unicode (utf8)
  2. mysql connection collation: utf8_general_ci
  3. your database , table collations set to: utf8_general_ci or utf8_unicode_ci

so when create table set charset utf8 :

create table my_table ( id int(11) not null auto_increment, name varchar(20) character set utf8 collate utf8_general_ci not null, primary key  (id) ) default charset=utf8; 

if have table encoded in latin1, convert :

alter table `my_table` convert character set utf8 

see : character set in mysql.

then, need add line in php when setup database connection :

mysql_query ('set names \'utf8\'');   

or :

mysql_set_charset ('utf8'); // php 5.2.3 or greater. 

or if you're using pdo, can pass 4th parameter :

$db = new pdo ('mysql:host=localhost;dbname=tests', 'root', '',                 array (pdo::mysql_attr_init_command => 'set names \'utf8\'')); 

also don't forget set header of pages utf8 :

header ('content-type:text/html; charset=utf-8'); 

example sorting query :

$sql = "select * my_table order name" ; 

hope helps.


Popular posts from this blog