1

im trying to sort names from sql

while($ddfg = mysql_fetch_array($result_skey002))
{
    $total = $ddfg['name2'];
}
sort($total);
echo $total;

Somthing like that ..,
Im work with name in hebrew so this its doesnt working:

$query_skey002 = "SELECT * FROM s_keywords ORDER BY `name2` ASC";

I have no idea how to work with php sort function.
Thanks for the helpers

2
  • Apart from the fact that you should do that in the database, you are overwriting your variable (a string) in the loop and feeding a string to an array function. Commented Jul 17, 2013 at 20:44
  • $total = $ddfg['name2']; should be $total[] = $ddfg['name2']; and echo $total should be something else Commented Jul 17, 2013 at 20:52

2 Answers 2

4

Don't sort in PHP. Your database query is doing that. No need to sort twice. MySQL can sort hebrew text if you use the correct charset/collation.

http://dev.mysql.com/doc/refman/5.0/en/charset-mysql.html

Update:

Here is a working example of inserting hebrew into a mysql table. I tested it and it definitely works:

mysql> create table hebrew_table (my_column varchar(128)) charset=hebrew;
Query OK, 0 rows affected (0.03 sec)

mysql> insert into hebrew_table (my_column) values ('אחד');
Query OK, 1 row affected (0.00 sec)

mysql> select * from hebrew_table;
+-----------+
| my_column |
+-----------+
| אחד       |
+-----------+
1 row in set (0.01 sec)
Sign up to request clarification or add additional context in comments.

16 Comments

Mysql query dont know to do that with hebrew.
Look to see if mysql supports a charset/collation that can sort hebrew.
@Niv_H - it should work in MySQL. Is the table using the utf8 character set and collation for that column and is your database connection using UTF8 as well for the client connection character set?
you might be able to cast as hebrew_general_ci
I tried.. sql not suppurt hebrew, when i insert string in hebrew its showing in gibberish
|
1

Your database query is proper. It will sort result when your SQL query get executed.

You may improve your select SQL query using below one..

$query_skey002 = "SELECT * FROM `s_keywords` ORDER BY `name2` ASC";

1 Comment

MySQL has very less support for other languages as well as php5.5 deprecated MYSQL. Try for MySQLi..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.