2013-02-10 68 views
1

当试图连接某些值时,我不断收到使用MySQL 5.5.27的错误。我搜索并看到了一堆charset的答案(无可否认,这是我头上的TAD),但我已将所有表格转换为字符集utf8-unicode-ci,但仍然出现错误。MySQL串联和排序错误的非法组合错误

当然有办法连接这些值,但我只是不知道如何。我是一位Oracle相对较新的人。

这里是SQL行:

concat(pl.last_name,'-',format(money,0)) 

我得到:

#1270 - Illegal mix of collations (latin1_swedish_ci,IMPLICIT), (utf8_unicode_ci,COERCIBLE), (utf8_unicode_ci,COERCIBLE) for operation 'concat' 

任何想法?

+0

也有类似的问题? http://stackoverflow.com/questions/6668989/how-can-i-force-the-value-of-a-mysql-query-to-use-a-particular-collat​​ion – 2013-02-10 20:07:23

+0

这一个也可以帮助:http: //stackoverflow.com/questions/7753608/illegal-mix-of-collat​​ions-for-operation-concat – 2013-02-10 20:15:34

+0

你的钱列是一个整数?如果不是,则无法使用格式,请参阅http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_format。 – 2013-02-10 23:07:51

回答

2

如果钱确实是一个VARCHAR中的数字,您可以使用cast。

试试这个:

concat_ws(pl.last_name,'-',cast(money AS unsigned)); // This is with decimals. 
concat(`pl.last_name,'-',substring_index(money,',',1)) // Without decimals. If you use . i.e. the American currency notation you can substitute , with an . 

编辑

你应该首先尝试:concat(pl.last_name,'-',format(money,0));

这是一个非常基本的PHP代码,你可以使用。

<?php 

function selecting_data(){ 

    $host = "host"; 
    $user = "username"; 
    $password = "password"; 
    $database = "database"; 
    $charset = "utf8"; 

    $link = mysqli_connect($host, $user, $password, $database); 
    mysqli_set_charset($charset, $link); 
    IF (!$link) { 
     echo('Unable to connect to the database!'); 
    } ELSE { 


     $query = "SELECT lastname, format(money,0) FROM mytable"; //Select query 
     $result = mysqli_query($link, $query); 
     while ($rows = mysqli_fetch_array($result, MYSQLI_BOTH)){ 
      echo $rows['lastname']."<br>".$rows['money'] ; 
     } 
    } 
    mysqli_close($link); 


} 
?> 

<html> 
<head><title>title</title></head> 
<body> 
<?PHP echo selecting_data(); ?> 
</body> 
</html> 
+0

但我相信我的代码正在吹响pl.last_name - 如果我没有弄错,那就是一直在“拉丁语”出现......并且为了完全披露,并且背叛我缺乏PHP技能,最初我有一行返回“concat(pl.last_name,'
',format(money,0))”作为交叉表查询的“单元格” - 将两个值强制到我的单元格中的两行上......但这就是离题...谢谢你的帮助! – user2059532 2013-02-10 23:37:18

+0

即我想我想让我的pl.last_name出现“unicode”与
和整数中的“$”一起使用。 – user2059532 2013-02-10 23:38:47

+0

Oke,但你不能在这样的查询内混合使用php/html和mysql。你可以用输出做到这一点,但不能用你发送给mysql服务器的查询。 – 2013-02-10 23:42:44